Don't trust a zero Windows file ID in samefile_nofollow - #14865
Open
RonnyPfannschmidt wants to merge 1 commit into
Open
Don't trust a zero Windows file ID in samefile_nofollow#14865RonnyPfannschmidt wants to merge 1 commit into
RonnyPfannschmidt wants to merge 1 commit into
Conversation
On Windows st_ino holds the file ID, which file systems are free to not support; WinFsp mounts such as sshfs-win report 0 for every file, because SFTP has no inode field to fill it from. os.path.samestat() then reports any two files on the volume as the same file, so the Windows short-path fallback in Session.collect() matched every node and nothing got pruned: passing a single file collected the whole suite. Treat a zero file ID as unknown and fall back to path comparison, which is what the other platforms do anyway. Fixes pytest-dev#14864. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
RonnyPfannschmidt
force-pushed
the
fix-14864-samefile-zero-file-id
branch
from
August 12, 2026 12:12
91ebef2 to
e25d981
Compare
bluetech
approved these changes
Aug 13, 2026
|
|
||
| Unlike Path.samefile(), does not resolve symlinks. | ||
|
|
||
| On Windows st_ino is the file ID, which file systems are free to not |
Member
There was a problem hiding this comment.
I would put this in a code comment, not in the docstring (it's an implementation detail IMO).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14864.
On Windows, when a collection argument's path does not compare equal to a collected node's path,
Session.collect()falls back tosamefile_nofollow()to account for 8.3 short paths (#11895). That fallback usesos.path.samestat(), i.e. it compares(st_dev, st_ino).On Windows
st_inois the file ID, and support for file IDs is file-system specific — a file system that has none reports0for every file, the same convention the neighbouringBY_HANDLE_FILE_INFORMATIONfields use for unsupported values. The reporter's drive is an sshfs (WinFsp) mount, where the chain is:ATTRShas no inode field, so sshfs never fillsst_ino(the identifier does not appear insshfs.cat all).set_stat()overwritesst_inowith its own node id unlessuse_inois given. WinFsp's FUSE layer has no such fallback: it discardsuse_inoand assignsFileInfo->IndexNumber = stbuf.st_inoverbatim.FILE_ID_INFO.FileIdandnFileIndexHigh/Loware therefore both0, and CPython passes that straight through tost_ino.So
os.path.samestat()reports every pair of files on the volume as the same file, every node matched, nothing got pruned, and passing a single file collected the whole suite. This is the long-standing python/cpython#78116 (samefile()should not use zero-valuedst_devandst_ino), which also affects Google Drive File Stream and WebDAV volumes.Fixed by treating a zero file ID as "unknown" in the Windows version of
samefile_nofollow(), so the caller falls back to plain path comparison — which is what every non-Windows platform does anyway, since thesamestat()fallback is win32-only. The short-path case from #11895 is local NTFS with real file IDs and keeps working; 8.3 short names are an NTFS/FAT feature that the affected mounts do not generate in the first place.Note that
_is_same()in the same module has the same weakness, but there a bogusTrueonly makes the import-mismatch check miss a mismatch rather than break collection, so I left it alone.🤖 Generated with Claude Code