def test_import_module_using_spec(
        self, b_is_package, insert_modules, tmp_path: Path
    ):
        """
        Verify that `_import_module_using_spec` can obtain a spec based on the path, thereby enabling the import.
        When importing, not only the target module is imported, but also the parent modules are recursively imported.
        """
        file_path = tmp_path / "a/b/c/demo.py"
        file_path.parent.mkdir(parents=True)
        file_path.write_text("my_name='demo'", encoding="utf-8")

        if b_is_package:
            (tmp_path / "a/b/__init__.py").write_text(
                "my_name='b.__init__'", encoding="utf-8"
            )

        mod = _import_module_using_spec(
            "a.b.c.demo",
            file_path,
            file_path.parent,
            insert_modules=insert_modules,
        )

        # target module is imported
        assert mod is not None
        assert spec_matches_module_path(mod.__spec__, file_path) is True

        mod_demo = sys.modules["a.b.c.demo"]
        assert "demo.py" in str(mod_demo)
        assert mod_demo.my_name == "demo"  # Imported and available for use

        # parent modules are recursively imported.
        mod_a = sys.modules["a"]
        mod_b = sys.modules["a.b"]
        mod_c = sys.modules["a.b.c"]

        assert mod_a.b is mod_b
        assert mod_a.b.c is mod_c
        assert mod_a.b.c.demo is mod_demo

        assert "namespace" in str(mod_a).lower()
        assert "namespace" in str(mod_c).lower()

        # Compatibility package and namespace package.
        if b_is_package:
            assert "namespace" not in str(mod_b).lower()
            assert "__init__.py" in str(mod_b).lower()  # Imported __init__.py
            assert mod_b.my_name == "b.__init__"  # Imported and available for use

        else:
            assert "namespace" in str(mod_b).lower()
            with pytest.raises(AttributeError):  # Not imported __init__.py
                assert mod_b.my_name

        Verify that `_import_module_using_spec` can obtain a spec based on the path, thereby enabling the import.
        When importing, not only the target module is imported, but also the parent modules are recursively imported.
        
testing/test_pathlib.py