summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-09 03:44:36 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-09 03:44:36 (GMT)
commit3843de3b0e107fd7ac62953874e8863bc17ff467 (patch)
tree1b3426557ee152d4f87b76edc42be29164cbad46 /Lib/test
parent60480454bc57c2a52225ca7ed4cb1374e707e73a (diff)
parent313fa9d3651a5edab0d8f0f3b41720818b80c19d (diff)
downloadcpython-3843de3b0e107fd7ac62953874e8863bc17ff467.zip
cpython-3843de3b0e107fd7ac62953874e8863bc17ff467.tar.gz
cpython-3843de3b0e107fd7ac62953874e8863bc17ff467.tar.bz2
#11910: merge with 3.2.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 428595b..c65ed2c 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -91,12 +91,14 @@ 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 value is True if the module was in sys.modules and
- False otherwise."""
+ 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
+ __import__(name)
saved = False
else:
del sys.modules[name]
@@ -106,8 +108,7 @@ def _save_and_remove_module(name, orig_modules):
def _save_and_block_module(name, orig_modules):
"""Helper function to save and block a module in sys.modules
- Return value is True if the module was in sys.modules and
- False otherwise."""
+ Return True if the module was in sys.modules, False otherwise."""
saved = True
try:
orig_modules[name] = sys.modules[name]
@@ -123,6 +124,7 @@ def import_fresh_module(name, fresh=(), blocked=(), deprecated=False):
the sys.modules cache is restored to its original state.
Modules named in fresh are also imported anew if needed by the import.
+ If one of these modules can't be imported, None is returned.
Importing of modules named in blocked is prevented while the fresh import
takes place.
@@ -144,6 +146,8 @@ def import_fresh_module(name, fresh=(), blocked=(), deprecated=False):
if not _save_and_block_module(blocked_name, orig_modules):
names_to_remove.append(blocked_name)
fresh_module = importlib.import_module(name)
+ except ImportError:
+ fresh_module = None
finally:
for orig_name, module in orig_modules.items():
sys.modules[orig_name] = module