@@ -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+ )
18631884def 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