pytest-expect-test
raw JSON → 0.1.0 verified Sat May 09 auth: no python
A lightweight pytest plugin providing an `expect` fixture for snapshot testing. Version 0.1.0 is the initial release, requiring Python >=3.5. Development appears low-frequency, with no recent updates.
pip install pytest-expect-test Common errors
error ImportError: cannot import name 'expect' ↓
cause Attempting to import `expect` directly from `pytest` or without installing the plugin.
fix
Run
pip install pytest-expect-test and use from pytest_expect_test import expect. error AttributeError: 'Test' object has no attribute 'expect' ↓
cause Using `self.expect` inside a test method in a class while `expect` is passed as a parameter. Not supported as class attribute.
fix
Use
expect as a function parameter in the test method: def test_example(self, expect): expect(...) Warnings
gotcha On first test run, the test passes regardless of the actual value because the expectation is recorded. Subsequent runs will fail if the actual value differs from recorded. ↓
fix Review the recorded expectations (typically stored in test directory) and commit them to version control.
gotcha The `expect` fixture must be used as a parameter in the test function; it is not a regular assertion. Do not call `expect()` as a function without the fixture injection. ↓
fix Define test with `def test_foo(expect):` to inject the fixture.
Imports
- expect wrong
import pytest_expect_testcorrectfrom pytest_expect_test import expect
Quickstart
def test_example(expect):
expect(2 + 2) == 4
# The first run records the expectation, subsequent runs compare.