Commit cd0f7bfd authored by Tarek Ziade's avatar Tarek Ziade

Issue #12113: make sure generated module is not reused on a second run

parent 311a2d1b
...@@ -196,13 +196,16 @@ class DistributionTestCase(support.TempdirManager, ...@@ -196,13 +196,16 @@ class DistributionTestCase(support.TempdirManager,
def test_hooks_get_run(self): def test_hooks_get_run(self):
temp_home = self.mkdtemp() temp_home = self.mkdtemp()
module_name = os.path.split(temp_home)[-1]
pyname = '%s.py' % module_name
config_file = os.path.join(temp_home, "config1.cfg") config_file = os.path.join(temp_home, "config1.cfg")
hooks_module = os.path.join(temp_home, "testhooks.py") hooks_module = os.path.join(temp_home, pyname)
self.write_file(config_file, textwrap.dedent(''' self.write_file(config_file, textwrap.dedent('''
[test_dist] [test_dist]
pre-hook.test = testhooks.log_pre_call pre-hook.test = %(modname)s.log_pre_call
post-hook.test = testhooks.log_post_call''')) post-hook.test = %(modname)s.log_post_call'''
% {'modname': module_name}))
self.write_file(hooks_module, textwrap.dedent(''' self.write_file(hooks_module, textwrap.dedent('''
record = [] record = []
...@@ -221,12 +224,17 @@ class DistributionTestCase(support.TempdirManager, ...@@ -221,12 +224,17 @@ class DistributionTestCase(support.TempdirManager,
# prepare the call recorders # prepare the call recorders
sys.path.append(temp_home) sys.path.append(temp_home)
self.addCleanup(sys.path.remove, temp_home) self.addCleanup(sys.path.remove, temp_home)
from testhooks import record record = __import__(module_name).record
old_run = cmd.run
old_finalize = cmd.finalize_options
cmd.run = lambda: record.append('run') cmd.run = lambda: record.append('run')
cmd.finalize_options = lambda: record.append('finalize') cmd.finalize_options = lambda: record.append('finalize')
try:
d.run_command('test_dist') d.run_command('test_dist')
finally:
cmd.run = old_run
cmd.finalize_options = old_finalize
self.assertEqual(record, ['finalize', self.assertEqual(record, ['finalize',
'pre-test_dist', 'pre-test_dist',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment