diff options
| author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-14 03:02:25 (GMT) | 
|---|---|---|
| committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-14 03:02:25 (GMT) | 
| commit | 720f8dea196640a053135f31be89b652d685e55c (patch) | |
| tree | d7e32654c4558d5b87902cff1114e1c5e1a0fd41 /Lib/test/test_support.py | |
| parent | d82a8876f0cf26ffc04d18f5fed0596c74c0d004 (diff) | |
| download | cpython-720f8dea196640a053135f31be89b652d685e55c.zip cpython-720f8dea196640a053135f31be89b652d685e55c.tar.gz cpython-720f8dea196640a053135f31be89b652d685e55c.tar.bz2  | |
Change import_fresh_module to work with packages.
Diffstat (limited to 'Lib/test/test_support.py')
| -rw-r--r-- | Lib/test/test_support.py | 16 | 
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index df4d124..04ab443 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -84,19 +84,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  | 
