Skip to content

Commit 07c7fbb

Browse files
Mulat MekonenMulat Mekonen
authored andcommitted
Skip symlink sibling test on Windows without symlink support #13771
1 parent b1e100d commit 07c7fbb

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ Mike Hoyle (hoylemd)
320320
Mike Lundy
321321
Milan Lesnek
322322
Miro Hrončok
323+
Mulat Mekonen
323324
mrbean-bremen
324325
Nathan Goldbaum
325326
Nathan Rousseau

changelog/13771.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip `test_do_not_collect_symlink_siblings` on Windows environments without symlink support to avoid false negatives.

testing/test_collection.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,27 +1860,41 @@ def test_pyargs_collection_tree(pytester: Pytester, monkeypatch: MonkeyPatch) ->
18601860
)
18611861

18621862

1863+
def _can_create_symlink(base: Path) -> bool:
1864+
"""Check if the current environment supports creating symlinks."""
1865+
target = base / "target"
1866+
link = base / "link"
1867+
try:
1868+
if target.exists():
1869+
target.rmdir() # remove old one if exists
1870+
target.mkdir()
1871+
1872+
if link.exists() or link.is_symlink():
1873+
link.unlink()
1874+
os.symlink(target, link, target_is_directory=True)
1875+
return link.is_symlink()
1876+
except (OSError, NotImplementedError):
1877+
return False
1878+
1879+
1880+
@pytest.mark.skipif(
1881+
sys.platform.startswith("win"),
1882+
reason="Symlink behavior on Windows depends on privileges / developer mode",
1883+
)
18631884
def test_do_not_collect_symlink_siblings(
18641885
pytester: Pytester, tmp_path: Path, request: pytest.FixtureRequest
18651886
) -> None:
1866-
"""
1867-
Regression test for #12039: Do not collect from directories that are symlinks to other directories in the same path.
1887+
if not _can_create_symlink(tmp_path):
1888+
pytest.skip("Symlinks not supported in this environment")
18681889

1869-
The check for short paths under Windows via os.path.samefile, introduced in #11936, also finds the symlinked
1870-
directory created by tmp_path/tmpdir.
1871-
"""
1872-
# Use tmp_path because it creates a symlink with the name "current" next to the directory it creates.
18731890
symlink_path = tmp_path.parent / (tmp_path.name[:-1] + "current")
18741891
assert symlink_path.is_symlink() is True
18751892

1876-
# Create test file.
18771893
tmp_path.joinpath("test_foo.py").write_text("def test(): pass", encoding="UTF-8")
18781894

1879-
# Ensure we collect it only once if we pass the tmp_path.
18801895
result = pytester.runpytest(tmp_path, "-sv")
18811896
result.assert_outcomes(passed=1)
18821897

1883-
# Ensure we collect it only once if we pass the symlinked directory.
18841898
result = pytester.runpytest(symlink_path, "-sv")
18851899
result.assert_outcomes(passed=1)
18861900

0 commit comments

Comments
 (0)