Skip to content

Commit 564e836

Browse files
committed
Correctly import submodules
1 parent 089116b commit 564e836

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

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

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

559-
mod = _import_module_using_spec(
560-
module_name, path, path.parent, insert_modules=True
561-
)
557+
mod = _import_module_using_spec(module_name, path, insert_modules=True)
562558
if mod is None:
563559
raise ImportError(f"Can't find module {module_name} at location {path}")
564560
return mod
@@ -611,7 +607,7 @@ def import_path(
611607

612608

613609
def _import_module_using_spec(
614-
module_name: str, module_path: Path, module_location: Path, *, insert_modules: bool
610+
module_name: str, module_path: Path, *, insert_modules: bool
615611
) -> Optional[ModuleType]:
616612
"""
617613
Tries to import a module by its canonical name, path to the .py file, and its
@@ -628,7 +624,7 @@ def _import_module_using_spec(
628624
# Checking with sys.meta_path first in case one of its hooks can import this module,
629625
# such as our own assertion-rewrite hook.
630626
for meta_importer in sys.meta_path:
631-
spec = meta_importer.find_spec(module_name, [str(module_location)])
627+
spec = meta_importer.find_spec(module_name, [str(module_path.parent)])
632628
if spec_matches_module_path(spec, module_path):
633629
break
634630
else:

0 commit comments

Comments
 (0)