def test_detect_meta_path(
        self,
        tmp_path: Path,
        monkeypatch: MonkeyPatch,
        pytester: Pytester,
    ) -> None:
        """
        resolve_pkg_root_and_module_name() considers sys.meta_path when importing namespace packages.

        Regression test for #12112.
        """

        class CustomImporter(importlib.abc.MetaPathFinder):
            """
            Imports the module name "com" as a namespace package.

            This ensures our namespace detection considers sys.meta_path, which is important
            to support all possible ways a module can be imported (for example editable installs).
            """

            def find_spec(
                self, name: str, path: Any = None, target: Any = None
            ) -> importlib.machinery.ModuleSpec | None:
                if name == "com":
                    spec = importlib.machinery.ModuleSpec("com", loader=None)
                    spec.submodule_search_locations = [str(com_root_2), str(com_root_1)]
                    return spec
                return None

        # Setup directories without configuring sys.path.
        models_py, algorithms_py = self.setup_directories(
            tmp_path, monkeypatch=None, pytester=pytester
        )
        com_root_1 = tmp_path / "src/dist1/com"
        com_root_2 = tmp_path / "src/dist2/com"

        # Because the namespace package is not setup correctly, we cannot resolve it as a namespace package.
        pkg_root, module_name = resolve_pkg_root_and_module_name(
            models_py, consider_namespace_packages=True
        )
        assert (pkg_root, module_name) == (
            tmp_path / "src/dist1/com/company",
            "app.core.models",
        )

        # Insert our custom importer, which will recognize the "com" directory as a namespace package.
        new_meta_path = [CustomImporter(), *sys.meta_path]
        monkeypatch.setattr(sys, "meta_path", new_meta_path)

        # Now we should be able to resolve the path as namespace package.
        pkg_root, module_name = resolve_pkg_root_and_module_name(
            models_py, consider_namespace_packages=True
        )
        assert (pkg_root, module_name) == (
            tmp_path / "src/dist1",
            "com.company.app.core.models",
        )

        resolve_pkg_root_and_module_name() considers sys.meta_path when importing namespace packages.

        Regression test for #12112.
        
testing/test_pathlib.py