mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
issue #18698: ensure importlib.reload() returns the module out of sys.modules.
This commit is contained in:
parent
e76c0393a8
commit
7491f1726b
3 changed files with 22 additions and 1 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue