pytest-snapshot
A plugin for snapshot testing with pytest.
What it is and what it does
pytest-snapshot is a pytest plugin that implements snapshot testing—a pattern where test assertions compare actual output against saved reference files (snapshots) rather than hardcoded expected values. When a function's output changes, you run pytest with --snapshot-update to regenerate snapshots, review the changes, and commit them to version control. This reduces boilerplate in tests and makes it easy to spot when behavior changes unexpectedly.
The plugin works with strings and bytes directly, and supports both single-file snapshots (via assert_match) and directory-based snapshot collections (via assert_match_dir). It gives you full control over snapshot file paths and serialization—you decide how to format output (JSON, YAML, plain text) before passing it to the snapshot method. The design is inspired by Jest's snapshot testing and emphasizes human-readable snapshots that are easy to review in code diffs and pull requests.
Use it for:
- Testing formatted output (JSON, YAML, HTML) where manual assertion maintenance is tedious.
- Regression testing large or complex data structures by comparing against golden files.
- Parametrized tests over many input cases, where each case's expected output is stored in a separate snapshot file.
- Verifying that refactoring or API changes produce expected output changes, with easy bulk review via --snapshot-update.
- Organizing test fixtures as readable snapshot files in version control rather than embedded test constants.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that enables snapshot testing—comparing test outputs against saved reference files to detect unexpected changes without manual assertion updates.
Yes, if you use pytest and want to reduce assertion boilerplate in tests with large or frequently-changing outputs. The low install friction and permissive license make adoption straightforward. However, maintenance is dormant; verify compatibility with your pytest and Python versions before relying on it for new projects, and monitor the repository for any compatibility issues.
Install
pytest-snapshot on PyPI
pip
pip install pytest-snapshotuv
uv add pytest-snapshotpoetry
poetry add pytest-snapshotInstalling pytest-snapshot
Before you install
Low friction; a single runtime dependency on pytest. Maintenance is dormant—last release was 2022-04-23—but the repository remains active and the package is stable at Beta status.
License in practice
MIT license is permissive; you may use, modify, and distribute this package freely in commercial and private projects without restriction.
Quickstart
pip install pytest-snapshot
# In your test file:
def test_output(snapshot):
result = some_function()
snapshot.assert_match(result, 'expected_output.txt')
# Run: pytest --snapshot-update
Requires pytest 3.0+; Python 3.5+.
Verify before relying
- Whether the dormant maintenance status affects compatibility with recent pytest or Python versions.
- Performance characteristics when snapshot testing large collections or deeply nested structures.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | dormant — 1,574 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,603,450/month — #2,971 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_snapshot-0.9.0-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI
snapshottestSnapshot testing library that captures API…
permissive · top 15,000 on PyPI
syrupySyrupy is a pytest plugin that enables snapshot…
permissive · top 5,000 on PyPI
pytest-instaA pytest plugin that enables snapshot testing…
unclear · top 15,000 on PyPI
inline-snapshotinline-snapshot is a pytest plugin that lets…
permissive · top 5,000 on PyPI
snapshot-restore-pyRegisters runtime hooks in AWS Lambda…
permissive · top 5,000 on PyPI
expecttestexpecttest implements inline golden tests where…
permissive · top 5,000 on PyPI
pytest-textual-snapshotA pytest plugin that captures SVG screenshots…
permissive · top 15,000 on PyPI
pytest-icdiffA pytest plugin that replaces default assertion…
permissive · top 5,000 on PyPI
pytest-loggingA pytest plugin that configures Python logging…
permissive · top 15,000 on PyPI