Syrupy

5.1.0 · active · verified Thu Apr 09

Syrupy is a pytest plugin for snapshot testing, enabling developers to capture the current output of a value and compare it against a previously stored snapshot. It's currently on version 5.1.0 and maintains an active release cadence, typically releasing minor/patch versions every 1-3 months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic snapshot test using the `snapshot` pytest fixture. The first run creates a snapshot file, and subsequent runs verify the data against it. The `--snapshot-update` flag is crucial for updating snapshots when expected data changes.

import pytest

def test_data_snapshot(snapshot):
    data = {
        "id": 123,
        "name": "Example Item",
        "details": [
            {"key": "value1", "status": "active"},
            {"key": "value2", "status": "inactive"}
        ]
    }
    assert data == snapshot

# To run this test:
# 1. Save as `test_snapshot.py`
# 2. Run `pytest` in your terminal
# 3. On the first run, a snapshot file will be created (e.g., `__snapshots__/test_snapshot.ambr`).
# 4. On subsequent runs, it will compare against the snapshot.
# 5. To update snapshots, run `pytest --snapshot-update`

view raw JSON →