skillfed

pytest-snapshot

A plugin for snapshot testing with pytest.

pytest-snapshot v0.9.0 2.6M downloads/30d#2,971 on PyPI138
Permissive license MIT DORMANT released

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-snapshot

uv

uv add pytest-snapshot

poetry

poetry add pytest-snapshot

Installing 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

Development Status :: 4 - BetaFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing

Tags

snapshot testing pytestregression testing with snapshotspytest output comparisongolden file testingsnapshot assertion testing
testingregression-testing

More Testing packages