Skip to content

Commit 6c0aa36

Browse files
committed
Correctly import submodules
1 parent c3488ce commit 6c0aa36

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
@@ -543,9 +543,7 @@ def import_path(
543543
with contextlib.suppress(KeyError):
544544
return sys.modules[module_name]
545545

546-
mod = _import_module_using_spec(
547-
module_name, path, pkg_root, insert_modules=False
548-
)
546+
mod = _import_module_using_spec(module_name, path, insert_modules=False)
549547
if mod is not None:
550548
return mod
551549

@@ -555,9 +553,7 @@ def import_path(
555553
with contextlib.suppress(KeyError):
556554
return sys.modules[module_name]
557555

558-
mod = _import_module_using_spec(
559-
module_name, path, path.parent, insert_modules=True
560-
)
556+
mod = _import_module_using_spec(module_name, path, insert_modules=True)
561557
if mod is None:
562558
raise ImportError(f"Can't find module {module_name} at location {path}")
563559
return mod
@@ -610,7 +606,7 @@ def import_path(
610606

611607

612608
def _import_module_using_spec(
613-
module_name: str, module_path: Path, module_location: Path, *, insert_modules: bool
609+
module_name: str, module_path: Path, *, insert_modules: bool
614610
) -> Optional[ModuleType]:
615611
"""
616612
Tries to import a module by its canonical name, path to the .py file, and its
@@ -627,7 +623,7 @@ def _import_module_using_spec(
627623
# Checking with sys.meta_path first in case one of its hooks can import this module,
628624
# such as our own assertion-rewrite hook.
629625
for meta_importer in sys.meta_path:
630-
spec = meta_importer.find_spec(module_name, [str(module_location)])
626+
spec = meta_importer.find_spec(module_name, [str(module_path.parent)])
631627
if spec is not None:
632628
break
633629
else:

0 commit comments

Comments
 (0)