fix mono-repo snapshot path lookup - #26
Open
alexrashed wants to merge 1 commit into
Open
Conversation
…tive nodeid Snapshot entries are keyed by the pytest nodeid, which is relative to pytest's rootdir. The committed *.snapshot.json / *.validation.json files assume the rootdir is the package containing the test, but pytest can be invoked with a different rootdir (e.g. VS Code pins --rootdir=<workspace folder> in multi-package workspaces), which prefixes every nodeid with the package directory and makes every snapshot lookup miss. Anchor the scope key to the nearest enclosing pyproject.toml so entries stay stable no matter where pytest was started from. Package-rooted runs produce unchanged keys, so existing snapshot files remain valid. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
bblommers
approved these changes
Aug 28, 2026
bblommers
left a comment
Contributor
There was a problem hiding this comment.
Makes sense! The logic is sound, and it looks we're covering all bases with the tests 👍
| path = Path(item.path) | ||
| for parent in path.parents: | ||
| if (parent / "pyproject.toml").is_file(): | ||
| _, separator, remainder = item.nodeid.partition("::") |
Contributor
There was a problem hiding this comment.
nitpick: This part actually confused me, probably because I expected partion() to work similar to split().
Do you think it's worth adding a comment to explain the expected input/output? E.g.:
# Partition splits by the first occurance and also returns the partition itself
# ("tests/test_thing.py", "::", "TestThing::test_case") == "tests/test_thing.py::TestThing::test_case".partition("::")
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
注册 for free
to join this conversation on GitHub.
Already have an account?
登录 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.
Motivation
We are currently re-designing our Python workspace setup, wher ewe have been facing an issue:
Snapshot entries are keyed by the pytest nodeid, which is relative to pytest's rootdir.
The committed *.snapshot.json / *.validation.json files assume the rootdir is the package containing the test, but pytest can be invoked with a different rootdir (e.g. VS Code pins --rootdir= in multi-package workspaces), which prefixes every nodeid with the package directory and makes every snapshot lookup miss.
Changes
Anchor the scope key to the nearest enclosing
pyproject.tomlso entries stay stable no matter wherepytestwas started from. Package-rooted runs produce unchanged keys, so existing snapshot files remain valid.