Fix inline snapshot closing """ indentation#496
Merged
MatthewMckee4 merged 4 commits intomainfrom Feb 24, 2026
Merged
Conversation
The closing `"""` of multiline inline snapshots was indented at the call's indentation level (e.g., 4 spaces) instead of the content's indentation level (e.g., 8 spaces). Fixed `generate_inline_literal()` to use `content_indent` for the closing delimiter.
Merging this PR will not alter performance
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When accepting or updating multiple inline snapshots in the same Python source file, each multiline expansion shifts line numbers for subsequent snapshots, causing wrong indentation, failed accepts, and corruption. Three fixes: - Compute indent from the actual call site line, not the (possibly stale) line_number parameter - Process batch accepts in descending line order (bottom-to-top) so edits at higher lines don't affect line numbers above - Pass function name in --snapshot-update path for defense-in-depth Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`containing_function_name` was returning the nearest `def` going backwards, which could be an inner class method (e.g. `__repr__`) rather than the enclosing test function. This caused function-name verification to fail, making `snapshot accept` error with "Could not find inline= argument". Fix by only considering `def` statements at strictly lower indentation than the call site, which correctly skips inner definitions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
generate_inline_literal()to indent the closing"""at the content indentation level (base + 4) instead of the call indentation level (base), aligning it with the snapshot content lines.test_inline_snapshot_multiline_closing_indentintegration test to verify correct closing delimiter indentation.Test plan
cargo nextest run -p karva_snapshotcargo nextest run -p karva -E 'test(inline)'just test(652/652)uvx prek run -a