pytest-ditto¶
Snapshot testing with minimal ceremony and flexible recorders.
-
Snapshot Testing
Record test outputs once, assert they don't change. No boilerplate.
-
Flexible Recorders
Strict JSON by default, built-in YAML, and plugins for specialised data.
-
Remote Backends
Store snapshots locally, on S3, in PostgreSQL, Redis, DuckDB — anywhere.
-
CLI Tools
Manage snapshots from the command line: list, update, prune, lint, and more.
Quick Example¶
import ditto
def fn(x: int) -> int:
return x + 1
def test_fn(snapshot) -> None:
result = fn(1)
assert result == snapshot(result, key="fn")
The first run records the result. Subsequent runs assert it hasn't changed.
How It Works¶
- Request the
snapshotfixture in your test function - Call
snapshot(value, key="name")— the value is persisted on first run, and every run returns it as the recorder reads it back - Assert equality — subsequent runs compare against the stored snapshot
- Choose a recorder — use
@ditto.yaml,@ditto.json, or any registered format
import ditto
@ditto.yaml
def test_config(snapshot):
config = load_config()
assert config == snapshot(config, key="config")
Installation¶
With optional recorder plugins: