summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-14 03:23:20 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-14 03:23:20 (GMT)
commit3659f27ad37f992fadc1692137edf32c01c5bc66 (patch)
treeac6031ed693319df45c90e8dfdac68dda9676367 /Lib
parente670c889ccf5ce7b27dedbc7d6d24e0679ca93bb (diff)
parentfec3ad103613b46c9821f210581efca6fedcb9a9 (diff)
downloadcpython-3659f27ad37f992fadc1692137edf32c01c5bc66.zip
cpython-3659f27ad37f992fadc1692137edf32c01c5bc66.tar.gz
cpython-3659f27ad37f992fadc1692137edf32c01c5bc66.tar.bz2
Merge with 3.1.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index cab366b..2a06661 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -92,19 +92,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