Pytest Check
pytest-check is a pytest plugin that extends standard pytest functionality to allow multiple assertion failures within a single test function without immediately stopping test execution. Instead of failing on the first `assert`, it collects all 'checks' and reports them at the end of the test. The current version is 2.8.0, and it maintains an active release cadence with regular updates.
Warnings
- deprecated The import pattern `import pytest_check as check` for using helper functions (e.g., `check.equal()`, `check.is_true()`) is deprecated. While it currently works, it will be removed in a future major version without a deprecation warning being emitted.
- breaking The default behavior for displaying pseudo-tracebacks changed in version 2.x. Only the first failure per test will now include a pseudo-traceback by default (`--check-max-tb=1`). Previously, more might have been shown.
- gotcha The pseudo-tracebacks used by `pytest-check` for multiple failures are generated via introspection, which can be slower than standard assert tracebacks. Limiting the number of pseudo-tracebacks (via `--check-max-tb`) is a performance optimization.
Install
-
pip install pytest-check
Imports
- check
from pytest_check import check
Quickstart
import httpx
from pytest_check import check
def test_httpx_get():
# This assert will stop the test immediately if it fails
r = httpx.get('https://www.example.org/')
assert r.status_code == 200
# These 'checks' will all run, collecting failures,
# even if one of them fails
with check:
assert r.is_redirect is False
with check:
assert r.encoding == 'utf-8'
with check:
assert 'Example Domain' in r.text
# pytest-check also provides helper functions for common assertions
check.equal(r.status_code, 200, msg='Status code not 200')