Registry / testing / pytest-runtime-xfail

pytest-runtime-xfail

JSON →
library1.1.1pypypiunverified

pytest-runtime-xfail is a pytest plugin that provides a `runtime_xfail` fixture, enabling tests to be marked as 'xfail' (expected to fail) dynamically during test execution. This is particularly useful for tests that might fail under specific, conditional circumstances (e.g., different operating systems, library versions, or data states) that cannot be determined at test collection time. The current version is 1.1.1, and its release cadence is generally low, with updates as needed for bug fixes or compatibility.

pip install pytest-runtime-xfail
INSTALL
IMPORT
SIG · PYTEST-RUNTIME-XFA
P
pytest-runtime-xfail
testingpythonv1.1.1
Install
2.7s avg
Import
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.1 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 30.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.7s · import 0.000s · 31MB
29MB installed
● package 29MB
Code
Verified usage

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

runtime_xfail
def test_example(runtime_xfail):
from pytest_runtime_xfail import runtime_xfail
`runtime_xfail` is provided as a pytest fixture; it should be requested directly in your test function signature, not imported from the package.

This quickstart demonstrates how to use the `runtime_xfail` fixture within a test function. The test requests `runtime_xfail` as an argument, and then calls it conditionally. If `runtime_xfail` is called, the test will be marked as 'XFAIL' (expected to fail) with the provided reason, even if subsequent assertions fail.

import platform def test_feature_on_linux_only(runtime_xfail): """This test expects to pass on Linux, fail on others.""" if platform.system() != "Linux": runtime_xfail(f"This feature is not supported on {platform.system()}") # Simulate a test that would fail on non-Linux systems assert platform.system() == "Linux", "Expected to be on Linux" def test_conditional_bug(runtime_xfail): """This test demonstrates runtime xfail for a known bug under a condition.""" # Imagine some condition based on a runtime value or environment is_bug_present = True # This would be dynamically determined if is_bug_present: runtime_xfail("Known bug #123 causing failure under this condition") # Simulate a failing assertion if the bug is present assert False, "This assertion will fail if bug is present and not xfailed"
Debug
Known issues
gotchaCalling `runtime_xfail()` without a reason string will raise a TypeError.
fix
Always provide a string argument to `runtime_xfail()` explaining why the test is being marked as xfail, e.g., `runtime_xfail('Known issue with X on Y platform')`.
affects: All versions
gotchaIf an assertion fails *before* `runtime_xfail()` is called within a test, the test will be marked as FAILED, not XFAIL. `runtime_xfail` needs to be called proactively.
fix
Place the `runtime_xfail()` call at the beginning of the conditional block, before any code that might cause the test to fail if the condition is met. Ensure `runtime_xfail` is called *before* any potentially failing assertions it is meant to 'cover'.
affects: All versions
gotchaMixing `pytest-runtime-xfail` with the static `@pytest.mark.xfail` can be confusing. While `runtime_xfail` takes precedence if called, using `@pytest.mark.xfail(run=False)` will prevent the test body (and thus `runtime_xfail`) from executing at all.
fix
Prefer `runtime_xfail` for conditions determined only at runtime. For conditions known at collection time (e.g., specific Python version or installed library), `@pytest.mark.xfail` or `@pytest.mark.skipif` are often more appropriate. Understand the interaction to avoid unexpected test outcomes.
affects: All versions
Upgrade
Version history
1.1.1latest on PyPI · released Oct 10, 2025
Audit
Dependencies
pytestrequiredThis is a pytest plugin and requires pytest to function.
Agent activity
19 hits · last 30 days
node
18
Resources
pytest-runtime-xfail — pip install pytest-runtime-xfail · libregistry