fix: resolve item.path to absolute in pytest_collection_modifyitems#925
Open
andre-vauvelle wants to merge 2 commits intotach-org:mainfrom
Open
fix: resolve item.path to absolute in pytest_collection_modifyitems#925andre-vauvelle wants to merge 2 commits intotach-org:mainfrom
andre-vauvelle wants to merge 2 commits intotach-org:mainfrom
Conversation
da63557 to
2687e72
Compare
The Rust extension's should_remove_items only matches absolute paths. pytest_collection_modifyitems was passing item.path (relative), causing changed test files to be incorrectly deselected.
8d2738e to
a494f8d
Compare
DetachHead
reviewed
Apr 11, 2026
| item for item in items if state.handler.should_remove_items(file_path=item.path) | ||
| item | ||
| for item in items | ||
| if state.handler.should_remove_items(file_path=item.path.resolve()) |
Collaborator
There was a problem hiding this comment.
pytest_collection_modifyitemspassesitem.pathdirectly to theshould_remove_items, butitem.pathcan be relative (e.g. when tests live in subdirectories liketests/).
would you mind providing a minimal repro of this issue? i can't seem to reproduce it myself. the tach repo itself has its tests located in a subdirectory (python/tests) and item.path seems to always be absolute no matter how i run it.
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.
Summary
pytest_collection_modifyitemspassesitem.pathdirectly to theshould_remove_items, butitem.pathcan be relative (e.g. when tests live in subdirectories liketests/). The Rust side only matches against absolute paths, so changed test files get incorrectly deselected — tach thinks they're unaffected.Fix: call
item.path.resolve()before passing toshould_remove_items.Why existing tests didn't catch this
The existing tests use
pytesterwhich creates all test files at the project root. When files are at the root, relative and absolute paths are equivalent, soitem.pathalready matches. The bug only manifests when tests are in subdirectories (the common real-world layout).A
pytestersubprocess also always provides absoluteitem.pathvalues, so even adding subdirectory integration tests doesn't reproduce the issue. The added unit test uses mocks to verifyresolve()is called, which does fail without the fix.Test plan
uv run pytest python/tests/test_pytest_plugin.py)