pytest-assume

2.4.3 · active · verified Sat Apr 11

pytest-assume is a pytest plugin that enhances test assertion behavior by allowing multiple failures within a single test. Instead of stopping test execution on the first failed assertion, it collects all failures reported via `pytest.assume()` and reports them at the end of the test, providing a comprehensive view of all issues. The current version is 2.4.3, with a regular release cadence addressing bug fixes and compatibility improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `pytest.assume()` directly and with the `with pytest.assume:` context manager. All `assume` calls within a test function are executed, and any failures are reported at the end, unlike standard `assert` statements that stop execution immediately.

import pytest

def test_multiple_conditions():
    # These assumptions will all be evaluated,
    # and all failures reported at the end of the test.
    pytest.assume(1 == 1, "This assumption should pass")
    pytest.assume(2 == 3, "Expected 2 to be 3, but it was not!")
    pytest.assume("hello" == "hello", "String comparison should pass")
    pytest.assume(5 > 10, "5 is not greater than 10")

    # Using the context manager for a group of assumptions
    with pytest.assume:
        pytest.assume(True, "Context manager assumption 1 (pass)")
        pytest.assume(False, "Context manager assumption 2 (fail)")

    # A standard assert would halt the test here if it failed,
    # but pytest.assume allows execution to continue.
    assert 1 == 1 # This line is reached even if pytest.assume() calls failed

view raw JSON →