def test_importmode_importlib_with_dataclass(
        self, tmp_path: Path, ns_param: bool
    ) -> None:
        """Ensure that importlib mode works with a module containing dataclasses (#7856)."""
        fn = tmp_path.joinpath("_src/tests/test_dataclass.py")
        fn.parent.mkdir(parents=True)
        fn.write_text(
            dedent(
                """
                from dataclasses import dataclass

                @dataclass
                class Data:
                    value: str
                """
            ),
            encoding="utf-8",
        )

        module = import_path(
            fn, mode="importlib", root=tmp_path, consider_namespace_packages=ns_param
        )
        Data: Any = getattr(module, "Data")
        data = Data(value="foo")
        assert data.value == "foo"
        assert data.__module__ == "_src.tests.test_dataclass"

        # Ensure we do not import the same module again (#11475).
        module2 = import_path(
            fn, mode="importlib", root=tmp_path, consider_namespace_packages=ns_param
        )
        assert module is module2
Ensure that importlib mode works with a module containing dataclasses (#7856).
testing/test_pathlib.py