approvaltests
Assertion/verification library to aid testing
What it is and what it does
ApprovalTests is a snapshot-based testing library that compares test output against previously approved golden-master files. Instead of writing brittle assertions for complex objects, you capture the actual output, review it in a diff tool, and approve it as the expected result. On subsequent runs, any deviation from the approved output triggers a diff comparison, letting you decide whether the change is intentional or a regression.
The library integrates with pytest and unittest, supports CLI invocation for cross-language testing, and includes reporters that launch external diff tools (like your system's native diff viewer or IDE integrations). It handles long strings, large arrays, HTML, and structured objects—scenarios where line-by-line assertion code becomes unwieldy. Extra dependencies unlock optional features like clipboard reporting, HTML verification, and pairwise test combination.
Use it for:
- Verify multi-line text output or formatted reports without writing fragile string comparisons.
- Test complex nested data structures (dicts, lists, objects) by comparing their serialized form to an approved snapshot.
- Review HTML generation or template output using a visual diff tool instead of regex assertions.
- Detect unintended changes in API responses or large JSON structures across test runs.
- Manage test data for exercises, katas, or green-field projects using the starter project template.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ApprovalTests provides a snapshot-based assertion library for testing complex outputs—long strings, large arrays, structured objects—by comparing results against golden-master files and launching diff tools to review changes.
Yes. ApprovalTests fills a genuine gap in Python testing: snapshot-based verification for outputs too complex for simple assertions. Active maintenance, low install friction, permissive license, no known vulnerabilities, and broad Python version support (3.10–3.14) make it a solid choice. Install it if you regularly test long strings, structured objects, or generated content where a diff tool beats manual assertion logic.
Install
approvaltests on PyPI
pip
pip install approvaltestsuv
uv add approvaltestspoetry
poetry add approvaltestsInstalling approvaltests
Before you install
Low install friction: pure Python wheel with no compiled dependencies. Active maintenance—last commit 2026-08-10, released 2026-08-02. Requires Python 3.10 or later; tested on 3.10, 3.11, 3.12, 3.13, 3.14.
License in practice
Apache-2.0 (permissive): you may use, modify, and distribute this package freely in commercial and open-source projects, provided you include a copy of the license and state any material changes.
Quickstart
pip install approvaltests
from approvaltests.approvals import verify
def test_simple():
result = "Hello ApprovalTests"
verify(result)
Requires pytest or unittest as your test runner; reporters (diff tools) are optional but recommended for viewing approval failures.
Verify before relying
- Whether the 10 runtime dependencies (pytest, beautifulsoup4, pyperclip, etc.) are all required or only needed for specific features.
- Performance characteristics when verifying very large objects or arrays.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 10 — pytest, empty-files, typing_extensions, pyperclip, beautifulsoup4, allpairspy, testfixtures, mock, psutil, approval_utilities |
| Maintenance | actively maintained — 12 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 167,975/month — #10,458 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: approvaltests-19.1.1-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
approval-utilitiesProvides utility functions and helpers for…
permissive · top 15,000 on PyPI
expecttestexpecttest implements inline golden tests where…
permissive · top 5,000 on PyPI
testtoolstesttools extends Python's standard unittest…
permissive · top 5,000 on PyPI
snapshottestSnapshot testing library that captures API…
permissive · top 15,000 on PyPI
qase-python-commonsProvides core configuration and SDK…
permissive · top 15,000 on PyPI
pytest-snapshotA pytest plugin that enables snapshot…
permissive · top 5,000 on PyPI
datadiffGenerates human-readable diffs of Python data…
permissive · top 15,000 on PyPI
pytest-clarityA pytest plugin that displays colored,…
permissive · top 15,000 on PyPI
pytest-instaA pytest plugin that enables snapshot testing…
unclear · top 15,000 on PyPI
pytest-html-reporterGenerates static HTML test reports from pytest…
permissive · top 15,000 on PyPI