Add child modules as attributes of parent modules. (#10338)

Failing to add child modules as attributes of parent module will prevent them from being accessible through parent module.

Fix #10337
This commit is contained in:
akhilramkee
2023-07-01 20:42:41 +05:30
committed by GitHub
parent ba60649680
commit 2f7415cfbc
3 changed files with 27 additions and 1 deletions

View File

@@ -592,3 +592,15 @@ class TestImportLibMode:
modules = {}
insert_missing_modules(modules, "")
assert modules == {}
def test_parent_contains_child_module_attribute(
self, monkeypatch: MonkeyPatch, tmp_path: Path
):
monkeypatch.chdir(tmp_path)
# Use 'xxx' and 'xxy' as parent names as they are unlikely to exist and
# don't end up being imported.
modules = {"xxx.tests.foo": ModuleType("xxx.tests.foo")}
insert_missing_modules(modules, "xxx.tests.foo")
assert sorted(modules) == ["xxx", "xxx.tests", "xxx.tests.foo"]
assert modules["xxx"].tests is modules["xxx.tests"]
assert modules["xxx.tests"].foo is modules["xxx.tests.foo"]