From 7ef189757eb0cc9a99b9dc79727f66f1e3c1d5c7 Mon Sep 17 00:00:00 2001 From: isra17 Date: Sun, 12 May 2024 16:49:39 -0400 Subject: [PATCH] pathlib: Fix module path used when using importlib with namespaces --- src/_pytest/pathlib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index e14c2acd328..d09aab61428 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -540,7 +540,7 @@ def import_path( # Try to import this module using the standard import mechanisms, but # without touching sys.path. try: - pkg_root, module_name = resolve_pkg_root_and_module_name( + _, module_name = resolve_pkg_root_and_module_name( path, consider_namespace_packages=consider_namespace_packages ) except CouldNotResolvePathError: @@ -551,7 +551,7 @@ def import_path( return sys.modules[module_name] mod = _import_module_using_spec( - module_name, path, pkg_root, insert_modules=False + module_name, path, path.parent, insert_modules=False ) if mod is not None: return mod