skillfed

expecttest

expecttest v0.3.0 2.3M downloads/30d#3,130 on PyPI88
Permissive license MIT AGING released

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 expecttest

uv

uv add expecttest

poetry

poetry add expecttest

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.9

Tags

golden tests pythoninline expect testsauto-update test assertionssnapshot testing inlineexpected output testing
snapshot-testingtest-automation

More Testing packages