Skip to content

Commit 43d31dd

Browse files
committed
main: use a better windows short-path comparison method
The previous check does not account for multiple levels of symlinks: given a -> b -> c, a would match b.
1 parent 678c1a1 commit 43d31dd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/_pytest/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -935,13 +935,11 @@ def collect(self) -> Iterator[nodes.Item | nodes.Collector]:
935935
is_match = node.path == matchparts[0]
936936
if sys.platform == "win32" and not is_match:
937937
# In case the file paths do not match, fallback to samefile() to
938-
# account for short-paths on Windows (#11895).
939-
same_file = os.path.samefile(node.path, matchparts[0])
940-
# We don't want to match links to the current node,
941-
# otherwise we would match the same file more than once (#12039).
942-
is_match = same_file and (
943-
os.path.islink(node.path)
944-
== os.path.islink(matchparts[0])
938+
# account for short-paths on Windows (#11895). But use a version
939+
# which doesn't resolve symlinks, otherwise we might match the
940+
# same file more than once (#12039).
941+
is_match = os.path.samestat(
942+
node.path.lstat(), matchparts[0].lstat()
945943
)
946944

947945
# Name part e.g. `TestIt` in `/a/b/test_file.py::TestIt::test_it`.

0 commit comments

Comments
 (0)