Skip to content

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Add name= keyword argument to karva.assert_snapshot() for user-defined snapshot names
  • Named snapshots produce files like test__test_page--header.snap using the -- convention
  • name= and inline= are mutually exclusive (enforced via typing overloads and runtime check)
  • Update base_function_name() to strip --name suffixes so karva snapshot prune works correctly with named snapshots
  • Parametrized named snapshots produce test__test_func--name(param=value).snap

Test plan

  • Unit tests for compute_named_snapshot (plain and parametrized)
  • Unit tests for base_function_name with -- suffixes
  • Integration test: named snapshot creates correct file
  • Integration test: named snapshot matches on second run
  • Integration test: named snapshot mismatch shows correct diff
  • Integration test: multiple named snapshots in same test
  • Integration test: mixed named + unnamed in same test
  • Integration test: name= + inline= raises TypeError
  • Integration test: named parametrized snapshots
  • Integration test: named snapshot prune
  • All 574 tests pass, prek run -a clean

Allow users to give meaningful names to snapshots via
`karva.assert_snapshot(value, name='my_snap')`, producing files like
`test__test_page--header.snap`. The `name=` and `inline=` parameters
are mutually exclusive, enforced via Python typing overloads and a
Rust runtime check.

Also updates `base_function_name()` to strip `--name` suffixes so
`karva snapshot prune` correctly identifies unreferenced named snapshots.
@MatthewMckee4 MatthewMckee4 merged commit 9d43f84 into main Feb 10, 2026
8 checks passed
@MatthewMckee4 MatthewMckee4 deleted the add-named-snapshots branch February 10, 2026 15:07
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 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 add-named-snapshots (22a765c) with main (42f0ff5)

Open in CodSpeed

@MatthewMckee4 MatthewMckee4 added the snapshot-testing Related to snapshot testing label 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.

1 participant