def test_importlib_package(
        self, monkeypatch: MonkeyPatch, tmp_path: Path, ns_param: bool
    ):
        """
        Importing a package using --importmode=importlib should not import the
        package's __init__.py file more than once (#11306).
        """
        monkeypatch.chdir(tmp_path)
        monkeypatch.syspath_prepend(tmp_path)

        package_name = "importlib_import_package"
        tmp_path.joinpath(package_name).mkdir()
        init = tmp_path.joinpath(f"{package_name}/__init__.py")
        init.write_text(
            dedent(
                """
                from .singleton import Singleton

                instance = Singleton()
                """
            ),
            encoding="ascii",
        )
        singleton = tmp_path.joinpath(f"{package_name}/singleton.py")
        singleton.write_text(
            dedent(
                """
                class Singleton:
                    INSTANCES = []

                    def __init__(self) -> None:
                        self.INSTANCES.append(self)
                        if len(self.INSTANCES) > 1:
                            raise RuntimeError("Already initialized")
                """
            ),
            encoding="ascii",
        )

        mod = import_path(
            init,
            root=tmp_path,
            mode=ImportMode.importlib,
            consider_namespace_packages=ns_param,
        )
        assert len(mod.instance.INSTANCES) == 1
        # Ensure we do not import the same module again (#11475).
        mod2 = import_path(
            init,
            root=tmp_path,
            mode=ImportMode.importlib,
            consider_namespace_packages=ns_param,
        )
        assert mod is mod2

        Importing a package using --importmode=importlib should not import the
        package's __init__.py file more than once (#11306).
        
testing/test_pathlib.py