Registry / testing / pytest-assume

pytest-assume

JSON →
library2.4.3pypypi✓ verified 25d ago

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.

pip install pytest-assume
INSTALL
IMPORT
SIG · PYTEST-ASSUME
P
pytest-assume
testingpythonv2.4.3
Install
2.8s avg
Import
392ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.4.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.412s · 31.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.372s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest.assume
import pytest # ... use pytest.assume()
pytest.assume() is exposed directly by the plugin once installed; no direct import from 'pytest_assume' module is typically needed for core functionality.

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
Debug
Known issues
gotchaUnlike standard Python `assert` statements, `pytest.assume()` does not immediately halt test execution upon failure. Its core purpose is to allow tests to continue running and collect all failures before reporting them at the end. This can be a surprise for users expecting traditional assertion behavior.
fix
Be mindful of this execution flow. If immediate halting is desired, use standard `assert` statements instead of `pytest.assume()` for critical conditions, or structure tests to run different failure types in separate functions.
affects: All versions
gotchapytest-assume has historically had nuanced interactions with other pytest plugins, particularly those that modify hook execution order or capture output (e.g., log capturing). While recent versions (e.g., 2.4.3) include fixes like `tryfirst=True` for specific hooks, conflicts can still arise. Previous versions also saw changes to internal pytest hooks used (e.g., 2.1.0, 2.4.0).
fix
Thoroughly test `pytest-assume` in your specific plugin environment. If unexpected behavior occurs, consult the `pytest-assume` GitHub issues or documentation, and consider using the latest version of the plugin and pytest itself.
affects: <=2.4.2 (specifically for log capture), but generally across all versions for potential hook conflicts.
gotchaWhen using `pytest-assume` with `xfail` markers, there have been bug fixes in how `xfail` conditions are handled in conjunction with multiple assumptions. While version 2.4.1 addressed specific bugs, unexpected interactions might still occur with complex `xfail` configurations.
fix
Ensure you are using `pytest-assume` version 2.4.1 or newer for improved `xfail` compatibility. Test your `xfail` cases carefully to confirm expected behavior.
affects: <2.4.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_assume'
The 'pytest-assume' package is not installed in the current Python environment.
fix
Install the package using pip: 'pip install pytest-assume'.
ImportError: cannot import name 'assume' from 'pytest'
Attempting to import 'assume' directly from 'pytest' instead of from 'pytest_assume'.
fix
Use the correct import statement: 'from pytest_assume import assume'.
AttributeError: module 'pytest' has no attribute 'assume'
Calling 'pytest.assume()' directly, which is not a method in the 'pytest' module.
fix
Import 'assume' from 'pytest_assume' and use it: 'from pytest_assume import assume'.
TypeError: assume() missing 1 required positional argument: 'expr'
Calling 'assume()' without providing the expression to be tested.
fix
Provide the expression to 'assume()', e.g., 'assume(x == y)'.
NameError: name 'assume' is not defined
Using 'assume()' without importing it from 'pytest_assume'.
fix
Import 'assume' with 'from pytest_assume import assume' before using it.
Upgrade
Version history
2.4.3latest on PyPI · released Jun 24, 2021
Audit
Dependencies
pytestrequiredpytest is the core test framework this plugin extends.
Agent activity
10 hits · last 30 days
node
8
Resources
pytest-assume — pip install pytest-assume · libregistry