Skip to content

Commit 752c51c

Browse files
flying-sheepnicoddemus
authored andcommitted
Correctly import submodules
1 parent 63d985c commit 752c51c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/_pytest/pathlib.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,7 @@ def import_path(
550550
with contextlib.suppress(KeyError):
551551
return sys.modules[module_name]
552552

553-
mod = _import_module_using_spec(
554-
module_name, path, pkg_root, insert_modules=False
555-
)
553+
mod = _import_module_using_spec(module_name, path, insert_modules=False)
556554
if mod is not None:
557555
return mod
558556

@@ -562,9 +560,7 @@ def import_path(
562560
with contextlib.suppress(KeyError):
563561
return sys.modules[module_name]
564562

565-
mod = _import_module_using_spec(
566-
module_name, path, path.parent, insert_modules=True
567-
)
563+
mod = _import_module_using_spec(module_name, path, insert_modules=True)
568564
if mod is None:
569565
raise ImportError(f"Can't find module {module_name} at location {path}")
570566
return mod
@@ -617,7 +613,7 @@ def import_path(
617613

618614

619615
def _import_module_using_spec(
620-
module_name: str, module_path: Path, module_location: Path, *, insert_modules: bool
616+
module_name: str, module_path: Path, *, insert_modules: bool
621617
) -> Optional[ModuleType]:
622618
"""
623619
Tries to import a module by its canonical name, path to the .py file, and its
@@ -630,7 +626,7 @@ def _import_module_using_spec(
630626
# Checking with sys.meta_path first in case one of its hooks can import this module,
631627
# such as our own assertion-rewrite hook.
632628
for meta_importer in sys.meta_path:
633-
spec = meta_importer.find_spec(module_name, [str(module_location)])
629+
spec = meta_importer.find_spec(module_name, [str(module_path.parent)])
634630
if spec_matches_module_path(spec, module_path):
635631
break
636632
else:

0 commit comments

Comments
 (0)