summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/test_api.py
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-12-15 04:27:28 (GMT)
committerMeador Inge <meadori@gmail.com>2011-12-15 04:27:28 (GMT)
commitd7afeeeb8dc8b4e2e59951a15b68f362282d447e (patch)
tree6e05ec5b94407e928228641563b41a47184137ee /Lib/importlib/test/test_api.py
parentabbcd0872fc970bb83d8ff5f0f09ca988c172360 (diff)
parent416f12ddb3b7d780bb75563414b88b32c0cf7e67 (diff)
downloadcpython-d7afeeeb8dc8b4e2e59951a15b68f362282d447e.zip
cpython-d7afeeeb8dc8b4e2e59951a15b68f362282d447e.tar.gz
cpython-d7afeeeb8dc8b4e2e59951a15b68f362282d447e.tar.bz2
Issue #13591: import_module potentially imports a module twice.
Diffstat (limited to 'Lib/importlib/test/test_api.py')
-rw-r--r--Lib/importlib/test/test_api.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py
index 0ffa3c4..a151626 100644
--- a/Lib/importlib/test/test_api.py
+++ b/Lib/importlib/test/test_api.py
@@ -67,6 +67,23 @@ class ImportModuleTests(unittest.TestCase):
importlib.import_module('.support')
+ def test_loaded_once(self):
+ # Issue #13591: Modules should only be loaded once when
+ # initializing the parent package attempts to import the
+ # module currently being imported.
+ b_load_count = 0
+ def load_a():
+ importlib.import_module('a.b')
+ def load_b():
+ nonlocal b_load_count
+ b_load_count += 1
+ code = {'a': load_a, 'a.b': load_b}
+ modules = ['a.__init__', 'a.b']
+ with util.mock_modules(*modules, module_code=code) as mock:
+ with util.import_state(meta_path=[mock]):
+ importlib.import_module('a.b')
+ self.assertEqual(b_load_count, 1)
+
def test_main():
from test.support import run_unittest
run_unittest(ImportModuleTests)