]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix possible failure in pickling tests due to different instantiations
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 16 Jul 2010 19:10:38 +0000 (19:10 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 16 Jul 2010 19:10:38 +0000 (19:10 +0000)
of the random module being around.

Lib/test/test_threaded_import.py

index 5b96d87e7614616fc9f25587f22904ad7fb1c63a..6cedb9615b45f20a830a19310919e2983fad8467 100644 (file)
@@ -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.