expecttest
What it is and what it does
expecttest is a testing library that implements golden tests with inline expectations—a pattern where you write tests with blank expected-output placeholders, run them to capture actual output, then rerun with EXPECTTEST_ACCEPT=1 to automatically populate the source code with the captured values. It works with both unittest and pytest, and supports multiline strings via triple-quoted literals.
The library modifies your Python test files directly when accepting new expectations, rather than storing them in external snapshot files. This keeps test logic and expectations in one place but requires careful version control practices. It's useful when you want to verify complex output (formatted strings, error messages, data structures) without manually writing expected values.
Use it for:
- Verify formatted output of code generators or transpilers by capturing and versioning the generated code inline.
- Test error messages and exception formatting by accepting the actual output as the expected baseline.
- Snapshot test complex data structure representations without maintaining separate snapshot files.
- Validate multi-line string output in documentation examples or report generation.
- Update test expectations in bulk when intentional API changes produce different but correct output.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
expecttest implements inline golden tests where expected outputs are stored directly in Python source code and automatically updated when you run tests with EXPECTTEST_ACCEPT=1.
Yes, if you prefer inline snapshots over external snapshot files and your team is comfortable with test files being modified during test runs. The library is stable, permissively licensed, and has no dependencies. The aging maintenance status is not a blocker for a mature, focused tool, but verify it still works smoothly with your pytest or unittest version before adopting it in a new project.
Install
expecttest on PyPI
pip
pip install expecttestuv
uv add expecttestpoetry
poetry add expecttestInstalling expecttest
Before you install
Low friction install with no runtime dependencies. Maintenance is aging—last release was 611 days ago—but the repository is active and not archived, with 88 stars.
License in practice
MIT license permits unrestricted use, modification, and distribution with only attribution required.
Quickstart
from expecttest import TestCase
class MyTest(TestCase):
def test_example(self):
self.assertExpectedInline(some_func(), """""")
# Run: EXPECTTEST_ACCEPT=1 python -m unittest
Verify before relying
- Whether the package works with pytest parameterization and fixtures beyond the documented Expect() pattern.
- Performance characteristics when updating large numbers of inline expectations in a single test run.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0.0,>=3.8.1) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 611 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,333,091/month — #3,130 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: expecttest-0.3.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
approvaltestsApprovalTests provides a snapshot-based…
permissive · top 15,000 on PyPI
approval-utilitiesProvides utility functions and helpers for…
permissive · top 15,000 on PyPI
snapshottestSnapshot testing library that captures API…
permissive · top 15,000 on PyPI
suresure provides fluent, chainable assertion…
copyleft · top 15,000 on PyPI
pytest-snapshotA pytest plugin that enables snapshot…
permissive · top 5,000 on PyPI
assertsProvides stand-alone assertion functions for…
unclear · top 15,000 on PyPI
expectsExpects is an assertion library for TDD/BDD…
permissive · top 15,000 on PyPI
lambdatest-selenium-driverCaptures visual snapshots during Selenium tests…
permissive · top 15,000 on PyPI
html-testRunnerA unittest test runner that generates…
permissive · top 15,000 on PyPI
inline-snapshotinline-snapshot is a pytest plugin that lets…
permissive · top 5,000 on PyPI