Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14514.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dots in test module filenames are now escaped with underscores to prevent ``pytest`` from misinterpreting them as package notation when computing the module name.
1 change: 1 addition & 0 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ def compute_module_name(root: Path, module_path: Path) -> str | None:
return None
if names[-1] == "__init__":
names.pop()
names = [p.replace(".", "_") for p in names]
return ".".join(names)


Expand Down
6 changes: 6 additions & 0 deletions testing/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,12 @@ def test_compute_module_name(tmp_path: Path) -> None:
== "src.app.bar"
)

assert compute_module_name(tmp_path, tmp_path / "foo.test.py") == "foo_test"
assert (
compute_module_name(tmp_path, tmp_path / "src/app/foo.test.py")
== "src.app.foo_test"
)


def validate_namespace_package(
pytester: Pytester, paths: Sequence[Path], modules: Sequence[str]
Expand Down