Skip to main content

snaptest

Snapshot testing for Python — automatically creates snapshots on first run, shows clear diffs on mismatch, pytest plugin included, and a CLI to manage snapshots. Zero dependencies.

PyPI version Python License: MIT


Installation

pip install snaptest

Quick Start

# pytest style
def test_api_response(snap):
    result = get_users()
    snap(result)   # creates snapshot on first run, asserts on next runs
# Update snapshots when output intentionally changes
pytest --snapshot-update
# or
SNAPTEST_UPDATE=1 pytest

Usage

pytest Fixture

def test_user_list(snap):
    users = api.get_users()
    snap(users)

def test_multiple_snapshots(snap):
    snap(api.get_users(),   key="users_list")
    snap(api.get_profile(), key="user_profile")

Standalone (without pytest)

from snaptest import snapshot

def test_output():
    result = transform_data(raw_input)
    snapshot(result)              # auto-named from function + line number
    snapshot(result, key="data")  # named snapshot

Updating Snapshots

# Via pytest flag
pytest --snapshot-update

# Via environment variable
SNAPTEST_UPDATE=1 pytest

# Programmatically
from snaptest import update_snapshot
update_snapshot(new_value, key="my_snapshot")

Snapshot Files

Snapshots are stored as human-readable text files next to your test files:

tests/
├── test_api.py
├── test_transform.py
└── __snapshots__/
    ├── test_api.snap
    └── test_transform.snap

Commit __snapshots__/ to version control so diffs are visible in PRs.

Snapshot file format

# snaptest snapshot file
# Do not edit manually

[test_user_list_1]
{
  "id": 1,
  "name": "Alice"
}
[/test_user_list_1]

Diff Output on Mismatch

When a snapshot doesn't match, you get a clear diff:

SnapshotMismatch: 'test_user_list_1'
Snapshot file: tests/__snapshots__/test_api.snap

─── Diff (- expected, + actual) ───────────────────────
--- expected (stored)
+++ actual (current)
@@ -1,5 +1,5 @@
 {
   "id": 1,
-  "name": "Alice",
+  "name": "Alice Smith",
   "active": true
 }
────────────────────────────────────────────────────────

To update: SNAPTEST_UPDATE=1 pytest

Supported Types

Type How it's stored
dict JSON with sorted keys
list, tuple JSON array
set, frozenset Sorted JSON array
str, int, float, bool, None JSON scalar
dataclass JSON via dataclasses.asdict
Any object with __dict__ JSON via vars()
Anything else repr()

CLI

# List all snapshot files and keys
snaptest list

# Show a stored snapshot value
snaptest show my_snapshot_key

# Instructions to update
snaptest update

# Delete all snapshot files (with confirmation)
snaptest clean
snaptest clean --yes   # skip confirmation

API Reference

snapshot(value, key=None, update=False)

Assert value matches stored snapshot. Creates on first run.

update_snapshot(value, key=None)

Force-update a snapshot.

snap fixture (pytest)

def test_something(snap):
    snap(value)              # auto-named
    snap(value, key="name")  # named

Running Tests

pip install pytest
pytest tests/ -v

License

MIT © prabhay759

Metadata

Release files for snaptestv2 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snaptestv2 1.0.0
File Size Uploaded Provenance Actions
snaptestv2-1.0.0.tar.gz 11.7 kB With provenance Details for snaptestv2-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snaptestv2 1.0.0
File Interpreter ABI Platform Actions
snaptestv2-1.0.0-py3-none-any.whl Python 3 none any Details for snaptestv2-1.0.0-py3-none-any.whl

Total release size: 22.3 kB

Release files / snaptestv2-1.0.0.tar.gz

Download URL snaptestv2-1.0.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dd756b1323007e7f12f6d5fc81688798577ba153feb49fe9445116e8dda02b29
BLAKE2b-256 checksum
How to use checksums
8b99d0527ab69fa2a705df17ec3a088b4ea179f6e1264ce52d00992c4d6e5d78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / snaptestv2-1.0.0-py3-none-any.whl

Download URL snaptestv2-1.0.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb5f86a08f21ebc22cedf3c9ad577e4bdd042723c5fa50ff2688bf66e1ff27e7
BLAKE2b-256 checksum
How to use checksums
3e3fd4e0574bd5e97e1a7965bac65a290dc9df8ef1bb41e2866d4a3dbe4bddd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Security for snaptestv2 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for snaptestv2-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page