diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2007-07-23 13:41:45 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2007-07-23 13:41:45 (GMT) |
commit | ae21fc6d1fa52d6c26cca797cf1f88cd45f2f143 (patch) | |
tree | dfd7715d7840307353631b43e280a41ccc901029 /Lib/test/test_runpy.py | |
parent | f17a2e4f874a7f3e21a442c5adbbe600de0718f5 (diff) | |
download | cpython-ae21fc6d1fa52d6c26cca797cf1f88cd45f2f143.zip cpython-ae21fc6d1fa52d6c26cca797cf1f88cd45f2f143.tar.gz cpython-ae21fc6d1fa52d6c26cca797cf1f88cd45f2f143.tar.bz2 |
Correctly cleanup sys.modules after executing runpy relative import
tests
Restore Python 2.4 ImportError when attempting to execute a package
(as imports cannot be guaranteed to work properly if you try it)
Diffstat (limited to 'Lib/test/test_runpy.py')
-rw-r--r-- | Lib/test/test_runpy.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py index f3bcb0b..e4ebc93 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -77,12 +77,16 @@ class RunModuleTest(unittest.TestCase): self.fail("Expected import error for " + mod_name) def test_invalid_names(self): + # Builtin module self.expect_import_error("sys") + # Non-existent modules self.expect_import_error("sys.imp.eric") self.expect_import_error("os.path.half") self.expect_import_error("a.bee") self.expect_import_error(".howard") self.expect_import_error("..eaten") + # Package + self.expect_import_error("logging") def test_library_module(self): run_module("runpy") @@ -115,13 +119,9 @@ class RunModuleTest(unittest.TestCase): return pkg_dir, mod_fname, mod_name def _del_pkg(self, top, depth, mod_name): - for i in range(depth+1): # Don't forget the module itself - parts = mod_name.rsplit(".", i) - entry = parts[0] - try: + for entry in list(sys.modules): + if entry.startswith("__runpy_pkg__"): del sys.modules[entry] - except KeyError, ex: - if verbose: print ex # Persist with cleaning up if verbose: print " Removed sys.modules entries" del sys.path[0] if verbose: print " Removed sys.path entry" |