mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Do a better job of preserving the state of sys.modules.
This commit is contained in:
parent
a34412a992
commit
ed843b5e5c
1 changed files with 6 additions and 1 deletions
|
@ -98,13 +98,18 @@ class FinderTests(unittest.TestCase):
|
||||||
new_path_hooks = [zipimport.zipimporter,
|
new_path_hooks = [zipimport.zipimporter,
|
||||||
_bootstrap.FileFinder.path_hook(
|
_bootstrap.FileFinder.path_hook(
|
||||||
*_bootstrap._get_supported_file_loaders())]
|
*_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[:],
|
with util.import_state(meta_path=sys.meta_path[:],
|
||||||
path=new_path,
|
path=new_path,
|
||||||
path_importer_cache=new_path_importer_cache,
|
path_importer_cache=new_path_importer_cache,
|
||||||
path_hooks=new_path_hooks):
|
path_hooks=new_path_hooks):
|
||||||
module = import_module('email')
|
module = import_module('email')
|
||||||
self.assertIsInstance(module, ModuleType)
|
self.assertIsInstance(module, ModuleType)
|
||||||
|
finally:
|
||||||
|
if email is not missing:
|
||||||
|
sys.modules['email'] = email
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue