[Python-checkins] cpython: test_import.test_module_with_large_stack(): unload the test module

victor.stinner python-checkins at python.org
Sun Oct 6 22:52:50 CEST 2013


http://hg.python.org/cpython/rev/a008c3c8d41a
changeset:   86138:a008c3c8d41a
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sun Oct 06 22:52:37 2013 +0200
summary:
  test_import.test_module_with_large_stack(): unload the test module

Ensure that the module is unloaded to be able to run the test more than once,
and to not leak memory.

files:
  Lib/test/test_import.py |  10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -149,16 +149,24 @@
         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:

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list