(self, tmp_path: Path)
| 723 | assert Data2.__module__ == "_src.m2.tests.test" |
| 724 | |
| 725 | def test_module_name_from_path(self, tmp_path: Path) -> None: |
| 726 | result = module_name_from_path(tmp_path / "src/tests/test_foo.py", tmp_path) |
| 727 | assert result == "src.tests.test_foo" |
| 728 | |
| 729 | # Path is not relative to root dir: use the full path to obtain the module name. |
| 730 | result = module_name_from_path(Path("/home/foo/test_foo.py"), Path("/bar")) |
| 731 | assert result == "home.foo.test_foo" |
| 732 | |
| 733 | # Importing __init__.py files should return the package as module name. |
| 734 | result = module_name_from_path(tmp_path / "src/app/__init__.py", tmp_path) |
| 735 | assert result == "src.app" |
| 736 | |
| 737 | # Unless __init__.py file is at the root, in which case we cannot have an empty module name. |
| 738 | result = module_name_from_path(tmp_path / "__init__.py", tmp_path) |
| 739 | assert result == "__init__" |
| 740 | |
| 741 | # Modules which start with "." are considered relative and will not be imported |
| 742 | # unless part of a package, so we replace it with a "_" when generating the fake module name. |
| 743 | result = module_name_from_path(tmp_path / ".env/tests/test_foo.py", tmp_path) |
| 744 | assert result == "_env.tests.test_foo" |
| 745 | |
| 746 | # We want to avoid generating extra intermediate modules if some directory just happens |
| 747 | # to contain a "." in the name. |
| 748 | result = module_name_from_path( |
| 749 | tmp_path / ".env.310/tests/test_foo.py", tmp_path |
| 750 | ) |
| 751 | assert result == "_env_310.tests.test_foo" |
| 752 | |
| 753 | def test_resolve_pkg_root_and_module_name( |
| 754 | self, tmp_path: Path, monkeypatch: MonkeyPatch, pytester: Pytester |
nothing calls this directly
no test coverage detected