Skip to content

Add snapshot testing#444

Merged
MatthewMckee4 merged 8 commits intomainfrom
snapshot-testing-feature
Feb 8, 2026
Merged

Add snapshot testing#444
MatthewMckee4 merged 8 commits intomainfrom
snapshot-testing-feature

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Add karva.assert_snapshot(value) API for file-based snapshot testing with support for named snapshots, multiple formats (str/repr/json), and parametrized tests
  • Add karva snapshot CLI with accept, reject, pending, and review subcommands for managing pending snapshots
  • New karva_snapshot crate handling snapshot storage, formatting, and diffing
  • Sanitize :: to __ in snapshot filenames for Windows filesystem compatibility
  • Forward --snapshot-update as CLI arg to workers instead of using unsafe set_var in main binary
  • Log warnings on setattr failures instead of silently discarding errors
  • Rename test helpers: command()test(), command_no_parallel()test_no_parallel(), add snapshot() method

Test plan

  • All 471 tests pass (just test)
  • All pre-commit checks pass (prek run -a)
  • No unsafe code in main binary (karva/src/lib.rs)
  • No :: in snapshot filesystem paths
  • Snapshot integration tests cover: creation, update, match, mismatch, named, formats, multiple per test, accept/reject/pending commands, parametrized tests

🤖 Generated with Claude Code

…a snapshot` CLI

Introduce file-based snapshot testing: `karva.assert_snapshot(value)` compares
values against stored `.snap` files, with `--snapshot-update` to accept changes
and `karva snapshot accept/reject/pending/review` for managing pending snapshots.

Key implementation details:
- New `karva_snapshot` crate for snapshot storage, formatting, and diffing
- Snapshot names sanitize `::` to `__` for Windows filesystem compatibility
- `--snapshot-update` forwarded as CLI arg to workers (no unsafe set_var in main binary)
- Snapshot attrs set on karva module with warning logging on failure
- Rename test helpers: `command()` → `test()`, `command_no_parallel()` → `test_no_parallel()`
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 8, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing snapshot-testing-feature (ccfd630) with main (02feadf)

Summary

✅ 1 untouched benchmark

MatthewMckee4 and others added 7 commits February 8, 2026 16:15
- Fix doubled module prefix in snapshot names by using function_name()
  instead of qualified_test_name for snapshot context
- Add colored diff output (red deletions, green insertions)
- Indent continuation lines in multi-line diagnostic error messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove the `expression` field from snapshot files since it was hardcoded
and not useful. Add line numbers to the `source` field using
`sys._getframe(0).f_lineno` (e.g. `test.py:5::test_hello`). Rewrite
diff output to use insta-style formatting with box-drawing characters,
dual line numbers, and colored headers. Add integration tests for the
`karva snapshot review` command covering accept, reject, skip, and
no-pending flows.
Widen line number columns from 4 to 5 chars so the `│` separator
aligns with `┬`/`┴` in border lines (both now at column 12).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rewrite diff rendering with context-aware grouping (grouped_ops),
word-level inline emphasis, and adaptive terminal width. Add insta-style
interactive review menu with colored keys, info/diff toggle actions,
skip-all support, and categorized summary output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 20 new integration tests covering multiline content, whitespace handling,
unicode, special characters, YAML-like content, empty strings, multiple files,
named snapshots, parametrized+named combinations, update overwrites, mixed
test results, multiline diffs, batch accept/reject/pending, and review actions
(accept-all, reject-all, mixed). Also fix test_print_changeset to match the
pipe separator change in diff output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover assert_snapshot() usage, formats (str/repr/json), named snapshots,
snapshot file format, --snapshot-update flag, CLI commands (accept, reject,
pending, review), and parametrized test integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MatthewMckee4 MatthewMckee4 merged commit ccbd066 into main Feb 8, 2026
8 checks passed
@MatthewMckee4 MatthewMckee4 deleted the snapshot-testing-feature branch February 8, 2026 22:08
@MatthewMckee4 MatthewMckee4 linked an issue Feb 8, 2026 that may be closed by this pull request
@MatthewMckee4 MatthewMckee4 added the snapshot-testing Related to snapshot testing label Feb 8, 2026
@MatthewMckee4 MatthewMckee4 changed the title Add snapshot testing feature Add snapshot testing Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot-testing Related to snapshot testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support snapshot testing

1 participant