Pytest Check

2.8.0 · active · verified Fri Apr 10

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

Install

Imports

Quickstart

This example demonstrates how to use `pytest-check` with both its `with check:` context manager for standard assertions and its direct helper functions like `check.equal()`. A normal `assert` outside of `with check:` will stop the test immediately, while checks inside the context manager or using `check.` methods will collect all failures before reporting them at the end of the test.

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')

view raw JSON →