Skip to content

Commit c875abe

Browse files
committed
Fixed the behavior on Windows.
1 parent 7dc7f33 commit c875abe

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/_pytest/nodes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def _recurse(self, dirpath: py.path.local) -> bool:
565565
return False
566566

567567
duplicate_paths = self.config.pluginmanager._duplicatepaths
568-
realpath = dirpath.realpath()
568+
realpath = _resolve_symlink(dirpath)
569569
if realpath in duplicate_paths:
570570
return False
571571
duplicate_paths.add(realpath)
@@ -600,7 +600,7 @@ def _collectfile(
600600
keepduplicates = self.config.getoption("keepduplicates")
601601
if not keepduplicates:
602602
duplicate_paths = self.config.pluginmanager._duplicatepaths
603-
resolved_path = path.realpath()
603+
resolved_path = _resolve_symlink(path)
604604
if resolved_path in duplicate_paths:
605605
return ()
606606
else:
@@ -670,3 +670,11 @@ def location(self) -> Tuple[str, Optional[int], str]:
670670
relfspath = self.session._node_location_to_relpath(fspath)
671671
assert type(location[2]) is str
672672
return (relfspath, location[1], location[2])
673+
674+
675+
def _resolve_symlink(local_path):
676+
"""
677+
The `LocalPath.realpath()` works fine on Linux, but on Windows, the symlinks are not resolved.
678+
This function makes sure that the symlink resolve is consistent.
679+
"""
680+
return local_path.__class__(Path(local_path.strpath).resolve())

testing/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ def test_collect_pkg_init_only(testdir):
12851285

12861286
@pytest.mark.parametrize("use_pkg", (True, False))
12871287
def test_collect_sub_with_symlinks(use_pkg, testdir):
1288-
"""Symlinked files won't be resolved again."""
1288+
"""Symlinked files won't be collected multiple times."""
12891289
sub = testdir.mkdir("sub")
12901290
if use_pkg:
12911291
sub.ensure("__init__.py")

0 commit comments

Comments
 (0)