Skip to content

Commit cbf4928

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

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,27 @@ 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:
@@ -1869,6 +1890,9 @@ def test_do_not_collect_symlink_siblings(
18691890
The check for short paths under Windows via os.path.samefile, introduced in #11936, also finds the symlinked
18701891
directory created by tmp_path/tmpdir.
18711892
"""
1893+
if not _can_create_symlink(tmp_path):
1894+
pytest.skip("Symlinks not supported in this environment")
1895+
18721896
# Use tmp_path because it creates a symlink with the name "current" next to the directory it creates.
18731897
symlink_path = tmp_path.parent / (tmp_path.name[:-1] + "current")
18741898
assert symlink_path.is_symlink() is True

0 commit comments

Comments
 (0)