]> granicus.if.org Git - python/commitdiff
test_import.test_module_with_large_stack(): unload the test module
authorVictor Stinner <victor.stinner@gmail.com>
Sun, 6 Oct 2013 20:52:37 +0000 (22:52 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Sun, 6 Oct 2013 20:52:37 +0000 (22:52 +0200)
Ensure that the module is unloaded to be able to run the test more than once,
and to not leak memory.

Lib/test/test_import.py

index 9d15a43be01d9f2f083a7b53a6b3478aea4b907c..a61ee2bcc0d209e5a0a30e6de13c1db25533f1f1 100644 (file)
@@ -149,16 +149,24 @@ class ImportTests(unittest.TestCase):
         sys.path.append('')
         importlib.invalidate_caches()
 
+        namespace = {}
         try:
             make_legacy_pyc(filename)
             # This used to crash.
-            exec('import ' + module)
+            exec('import ' + module, None, namespace)
         finally:
             # Cleanup.
             del sys.path[-1]
             unlink(filename + 'c')
             unlink(filename + 'o')
 
+            # Remove references to the module (unload the module)
+            namespace.clear()
+            try:
+                del sys.modules[module]
+            except KeyError:
+                pass
+
     def test_failing_import_sticks(self):
         source = TESTFN + ".py"
         with open(source, "w") as f: