]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Close #17731: Clean up properly in test_import
authorNick Coghlan <ncoghlan@gmail.com>
Mon, 15 Apr 2013 12:56:51 +0000 (22:56 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Mon, 15 Apr 2013 12:56:51 +0000 (22:56 +1000)
Lib/test/test_import.py

index 81ddf45330781b8c59c891b32ecfb092c806ab82..470a6d23927db1c8bc123de225033af849cf2d2d 100644 (file)
@@ -43,6 +43,7 @@ def _ready_to_import(name=None, source=""):
     # sets up a temporary directory and removes it
     # creates the module file
     # temporarily clears the module from sys.modules (if any)
+    # reverts or removes the module when cleaning up
     name = name or "spam"
     with script_helper.temp_dir() as tempdir:
         path = script_helper.make_script(tempdir, name, source)
@@ -54,6 +55,8 @@ def _ready_to_import(name=None, source=""):
         finally:
             if old_module is not None:
                 sys.modules[name] = old_module
+            elif name in sys.modules:
+                del sys.modules[name]
 
 
 class ImportTests(unittest.TestCase):