Skip to content

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

  1. Request the snapshot fixture in your test function
  2. Call snapshot(value, key="name") — the value is persisted on first run, and every run returns it as the recorder reads it back
  3. Assert equality — subsequent runs compare against the stored snapshot
  4. 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

pip install pytest-ditto

With optional recorder plugins:

pip install pytest-ditto[pandas]    # pandas DataFrames
pip install pytest-ditto[polars]    # polars DataFrames
pip install pytest-ditto[pyarrow]   # PyArrow Tables

Get Started CLI Reference