From 07930c40fc9379edb0b222b9022f737746f64ae8 Mon Sep 17 00:00:00 2001 From: Abhishek Hiremath <131762197+Abhi-DevHub@users.noreply.github.com> Date: Tue, 21 Jul 2026 23:21:06 +0530 Subject: [PATCH 1/4] Allow dotted test filenames via dot-escape in compute_module_name --- src/_pytest/pathlib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 291bdf4ecbf..8024092af8e 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -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) From f39a58fa801ba8558bb574055ad7b59b6427ec1f Mon Sep 17 00:00:00 2001 From: Abhishek Hiremath <131762197+Abhi-DevHub@users.noreply.github.com> Date: Tue, 21 Jul 2026 23:22:01 +0530 Subject: [PATCH 2/4] Add tests for dotted test filenames in compute_module_name --- testing/test_pathlib.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py index bd85b7e8fb4..a5aacdfccc1 100644 --- a/testing/test_pathlib.py +++ b/testing/test_pathlib.py @@ -1734,6 +1734,15 @@ 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] From ce1d906b4cb85cf274aefff19321ca6e683330c0 Mon Sep 17 00:00:00 2001 From: Abhishek Hiremath <131762197+Abhi-DevHub@users.noreply.github.com> Date: Tue, 21 Jul 2026 23:35:34 +0530 Subject: [PATCH 3/4] Add changelog entry for #14514 --- changelog/14514.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/14514.bugfix.rst diff --git a/changelog/14514.bugfix.rst b/changelog/14514.bugfix.rst new file mode 100644 index 00000000000..9d426952acd --- /dev/null +++ b/changelog/14514.bugfix.rst @@ -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. From 79fb34be0213505f2973bf567da9defc027db8e6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:06:12 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- testing/test_pathlib.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py index a5aacdfccc1..5d4c85bd6c0 100644 --- a/testing/test_pathlib.py +++ b/testing/test_pathlib.py @@ -1734,10 +1734,7 @@ 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 / "foo.test.py") == "foo_test" assert ( compute_module_name(tmp_path, tmp_path / "src/app/foo.test.py") == "src.app.foo_test"