Skip to content

main: use a better windows short-path comparison method #13598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,13 +935,11 @@ def collect(self) -> Iterator[nodes.Item | nodes.Collector]:
is_match = node.path == matchparts[0]
if sys.platform == "win32" and not is_match:
# In case the file paths do not match, fallback to samefile() to
# account for short-paths on Windows (#11895).
same_file = os.path.samefile(node.path, matchparts[0])
# We don't want to match links to the current node,
# otherwise we would match the same file more than once (#12039).
is_match = same_file and (
os.path.islink(node.path)
== os.path.islink(matchparts[0])
# account for short-paths on Windows (#11895). But use a version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the logic into a function in compat and add a unittests?

# which doesn't resolve symlinks, otherwise we might match the
# same file more than once (#12039).
is_match = os.path.samestat(
node.path.lstat(), matchparts[0].lstat()
)

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