diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-07-16 19:10:38 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-07-16 19:10:38 (GMT) |
commit | 448acd0a3f076c5e84266741445b3dfb6f28dfeb (patch) | |
tree | 912b923dd268b6c4e2611e5c427fd68514063acd /Lib/test/test_threaded_import.py | |
parent | 3b0a19eaba872c37eb2a0c84d3dcd79353250796 (diff) | |
download | cpython-448acd0a3f076c5e84266741445b3dfb6f28dfeb.zip cpython-448acd0a3f076c5e84266741445b3dfb6f28dfeb.tar.gz cpython-448acd0a3f076c5e84266741445b3dfb6f28dfeb.tar.bz2 |
Fix possible failure in pickling tests due to different instantiations
of the random module being around.
Diffstat (limited to 'Lib/test/test_threaded_import.py')
-rw-r--r-- | Lib/test/test_threaded_import.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py index 5b96d87..6cedb96 100644 --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -27,6 +27,16 @@ def task(N, done, done_tasks, errors): class ThreadedImportTests(unittest.TestCase): + def setUp(self): + self.old_random = sys.modules.pop('random', None) + + def tearDown(self): + # If the `random` module was already initialized, we restore the + # old module at the end so that pickling tests don't fail. + # See http://bugs.python.org/issue3657#msg110461 + if self.old_random is not None: + sys.modules['random'] = self.old_random + def test_parallel_module_init(self): if imp.lock_held(): # This triggers on, e.g., from test import autotest. |