From 96f72c150625bf85dfb1fd64f4f44b5e4480008c Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 3 Mar 2024 08:57:48 -0300 Subject: [PATCH] Add test and tweak changelog --- changelog/12039.bugfix.rst | 2 +- testing/test_collection.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/changelog/12039.bugfix.rst b/changelog/12039.bugfix.rst index 1ff40b177..267eae6b8 100644 --- a/changelog/12039.bugfix.rst +++ b/changelog/12039.bugfix.rst @@ -1 +1 @@ -Fixed a regression in 8.0.2 where tests have been collected multiple times in the CI under Windows +Fixed a regression in ``8.0.2`` where tests created using :fixture:`tmp_path` have been collected multiple times in CI under Windows. diff --git a/testing/test_collection.py b/testing/test_collection.py index 910dba3e6..d384ae97b 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -1789,6 +1789,26 @@ def test_collect_short_file_windows(pytester: Pytester) -> None: assert result.parseoutcomes() == {"passed": 1} +def test_not_collect_symlink_syblings( + pytester: Pytester, tmp_path: Path, request: pytest.FixtureRequest +) -> None: + """ + Do not collect from directories that are symlinks to other directories in the same path. + + The check for short paths under Windows via os.path.samefile, introduced in #11936, also finds the symlinked + directory created by tmp_path/tmpdir. + + #12039 + """ + # Use tmp_path because it creates a symlink with the name "current" next to the directory it creates. + assert tmp_path.parent.joinpath(f"{request.node.name}current").is_symlink() is True + + tmp_path.joinpath("test_foo.py").write_text("def test(): pass", encoding="UTF-8") + + result = pytester.runpytest_subprocess(tmp_path, "-sv") + result.assert_outcomes(passed=1) + + def test_pyargs_collection_tree(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: """When using `--pyargs`, the collection tree of a pyargs collection argument should only include parents in the import path, not up to confcutdir.