Skip to content

Comments

Fix inline snapshot closing """ indentation#496

Merged
MatthewMckee4 merged 4 commits intomainfrom
fix/inline-snapshot-closing-indent
Feb 24, 2026
Merged

Fix inline snapshot closing """ indentation#496
MatthewMckee4 merged 4 commits intomainfrom
fix/inline-snapshot-closing-indent

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Fixed 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.
  • Added test_inline_snapshot_multiline_closing_indent integration test to verify correct closing delimiter indentation.
  • Updated existing test snapshots affected by the indentation fix.

Test plan

  • Unit tests pass: cargo nextest run -p karva_snapshot
  • Integration tests pass: cargo nextest run -p karva -E 'test(inline)'
  • Full test suite passes: just test (652/652)
  • Pre-commit checks pass: uvx prek run -a

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.
@MatthewMckee4 MatthewMckee4 added the bug Something isn't working label Feb 22, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 22, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 1 untouched benchmark


Comparing fix/inline-snapshot-closing-indent (6d691b0) with main (b19404e)

Open in CodSpeed

MatthewMckee4 and others added 3 commits February 24, 2026 12:18
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>
@MatthewMckee4 MatthewMckee4 merged commit 1f872b4 into main Feb 24, 2026
9 checks passed
@MatthewMckee4 MatthewMckee4 deleted the fix/inline-snapshot-closing-indent branch February 24, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant