]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Change import_fresh_module to work with packages.
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 14 May 2011 03:02:25 +0000 (06:02 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 14 May 2011 03:02:25 +0000 (06:02 +0300)
Lib/test/support.py

index b2f0f87e65849993eeca93b4cbf11643daf19ba0..dcfadeaab6446fd3dca4bbe737e6f341af09046b 100644 (file)
@@ -80,19 +80,15 @@ def import_module(name, deprecated=False):
 def _save_and_remove_module(name, orig_modules):
     """Helper function to save and remove a module from sys.modules
 
-       Return True if the module was in sys.modules, False otherwise.
        Raise ImportError if the module can't be imported."""
-    saved = True
-    try:
-        orig_modules[name] = sys.modules[name]
-    except KeyError:
-        # try to import the module and raise an error if it can't be imported
+    # try to import the module and raise an error if it can't be imported
+    if name not in sys.modules:
         __import__(name)
-        saved = False
-    else:
         del sys.modules[name]
-    return saved
-
+    for modname in list(sys.modules):
+        if modname == name or modname.startswith(name + '.'):
+            orig_modules[modname] = sys.modules[modname]
+            del sys.modules[modname]
 
 def _save_and_block_module(name, orig_modules):
     """Helper function to save and block a module in sys.modules