Skip to content

fix: resolve item.path to absolute in pytest_collection_modifyitems#925

Open
andre-vauvelle wants to merge 2 commits intotach-org:mainfrom
andre-vauvelle:fix/pytest-plugin-resolve-item-path
Open

fix: resolve item.path to absolute in pytest_collection_modifyitems#925
andre-vauvelle wants to merge 2 commits intotach-org:mainfrom
andre-vauvelle:fix/pytest-plugin-resolve-item-path

Conversation

@andre-vauvelle
Copy link
Copy Markdown
Contributor

@andre-vauvelle andre-vauvelle commented Apr 10, 2026

Summary

pytest_collection_modifyitems passes item.path directly to the should_remove_items, but item.path can be relative (e.g. when tests live in subdirectories like tests/). 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 to should_remove_items.

Why existing tests didn't catch this

The existing tests use pytester which creates all test files at the project root. When files are at the root, relative and absolute paths are equivalent, so item.path already matches. The bug only manifests when tests are in subdirectories (the common real-world layout).

A pytester subprocess also always provides absolute item.path values, so even adding subdirectory integration tests doesn't reproduce the issue. The added unit test uses mocks to verify resolve() is called, which does fail without the fix.

Test plan

  • Existing tests pass (uv run pytest python/tests/test_pytest_plugin.py)
  • New unit test fails without fix, passes with fix

@andre-vauvelle andre-vauvelle force-pushed the fix/pytest-plugin-resolve-item-path branch 2 times, most recently from da63557 to 2687e72 Compare April 10, 2026 13:15
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.
@andre-vauvelle andre-vauvelle force-pushed the fix/pytest-plugin-resolve-item-path branch from 8d2738e to a494f8d Compare April 10, 2026 13:37
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())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pytest_collection_modifyitems passes item.path directly to the should_remove_items, but item.path can be relative (e.g. when tests live in subdirectories like tests/).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants