diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2013-08-15 00:03:34 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2013-08-15 00:03:34 (GMT) |
commit | 7491f1726ba3a5f78beddca2280f9141d559ff1c (patch) | |
tree | a272bd5852fe3662a81dfc78481f6aa88a68a870 /Lib/test/test_imp.py | |
parent | e76c0393a8dc35af38d6d2af2827f405a7ef6116 (diff) | |
download | cpython-7491f1726ba3a5f78beddca2280f9141d559ff1c.zip cpython-7491f1726ba3a5f78beddca2280f9141d559ff1c.tar.gz cpython-7491f1726ba3a5f78beddca2280f9141d559ff1c.tar.bz2 |
issue #18698: ensure importlib.reload() returns the module out of sys.modules.
Diffstat (limited to 'Lib/test/test_imp.py')
-rw-r--r-- | Lib/test/test_imp.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 3fb119b..bf29e42 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -5,6 +5,7 @@ import os.path import shutil import sys from test import support +from test.test_importlib import util import unittest import warnings @@ -285,6 +286,22 @@ class ReloadTests(unittest.TestCase): with self.assertRaisesRegex(ImportError, 'html'): imp.reload(parser) + def test_module_replaced(self): + # see #18698 + def code(): + module = type(sys)('top_level') + module.spam = 3 + sys.modules['top_level'] = module + mock = util.mock_modules('top_level', + module_code={'top_level': code}) + with mock: + with util.import_state(meta_path=[mock]): + module = importlib.import_module('top_level') + reloaded = imp.reload(module) + actual = sys.modules['top_level'] + self.assertEqual(actual.spam, 3) + self.assertEqual(reloaded.spam, 3) + class PEP3147Tests(unittest.TestCase): """Tests of PEP 3147.""" |