From ed843b5e5c7e222a54d89aaadb0a8342d06140a3 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 20 Nov 2012 17:10:10 -0500 Subject: [PATCH] Do a better job of preserving the state of sys.modules. --- Lib/test/test_importlib/import_/test_path.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py index 8b9c77dbf8c..d82b7f6b0c1 100644 --- a/Lib/test/test_importlib/import_/test_path.py +++ b/Lib/test/test_importlib/import_/test_path.py @@ -98,13 +98,18 @@ class FinderTests(unittest.TestCase): new_path_hooks = [zipimport.zipimporter, _bootstrap.FileFinder.path_hook( *_bootstrap._get_supported_file_loaders())] - with util.uncache('email'): + missing = object() + email = sys.modules.pop('email', missing) + try: with util.import_state(meta_path=sys.meta_path[:], path=new_path, path_importer_cache=new_path_importer_cache, path_hooks=new_path_hooks): module = import_module('email') self.assertIsInstance(module, ModuleType) + finally: + if email is not missing: + sys.modules['email'] = email def test_main():