skillfed

pytest-runtime-xfail

Call runtime_xfail() to mark running test as xfail.

pytest-runtime-xfail v1.1.1 179.9K downloads/30d#10,159 on PyPI5
Permissive license MIT License Copyright (c) 2021 Brian Okken Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) AGING released

What it is and what it does

pytest-runtime-xfail fills a gap in pytest's xfail handling by allowing you to decide at runtime whether a test should be marked as expected-to-fail, while still running the test to completion. The standard pytest.xfail() call stops test execution immediately; @pytest.mark.xfail() requires the decision at collection time. This plugin's runtime_xfail fixture lets you make that decision based on conditions known only during test execution, and the test continues running so you can see both XFAIL (test failed as expected) and XPASS (test passed unexpectedly) outcomes.

The fixture works by adding an xfail marker to the test node dynamically, similar to calling request.node.add_marker(pytest.mark.xfail()) but packaged as a reusable fixture. It respects the xfail_strict configuration option, so passing tests marked with runtime_xfail will fail the test run if strict mode is enabled—useful for detecting when previously-failing tests start passing.

Use it for:

  • Mark tests as xfail when a runtime condition (e.g., OS, Python version, or environment variable) indicates expected failure.
  • Conditionally expect failure in a shared fixture that multiple tests depend on, based on setup-time detection.
  • Track when platform-specific or version-specific test failures are resolved by using xfail_strict to catch XPASS.
  • Avoid skipping tests while still recording them as expected failures when a runtime dependency or feature is unavailable.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A pytest plugin that provides a `runtime_xfail` fixture to mark tests as expected-to-fail based on runtime conditions, allowing both XFAIL and XPASS outcomes.

Yes, if you need runtime-conditional xfail marking in pytest. The plugin solves a real gap in pytest's built-in xfail mechanisms and has no security vulnerabilities. Install friction is minimal. The aging maintenance status (308 days since last release) is a minor concern for a stable, single-purpose fixture, but the repository is not archived and the package is marked Production/Stable.

Install

pytest-runtime-xfail on PyPI

pip

pip install pytest-runtime-xfail

uv

uv add pytest-runtime-xfail

poetry

poetry add pytest-runtime-xfail

Installing pytest-runtime-xfail

Before you install

Low install friction; single pytest dependency. Maintenance status is aging—last release 308 days ago—but the repository remains active and the package is marked Production/Stable.

License in practice

MIT License permits unrestricted use, modification, and distribution with only attribution and liability disclaimer required.

Quickstart

pip install pytest-runtime-xfail

import pytest

def test_something(runtime_xfail):
    if runtime_condition:
        runtime_xfail(reason="explanation")
    assert True  # test continues to run

Verify before relying

  • Whether the plugin works correctly with pytest parametrization and xfail_strict in all supported Python versions.
  • Performance impact when runtime_xfail is called in fixtures used by many tests.

Package facts

License MIT License Copyright (c) 2021 Brian Okken Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance aging — 308 days since the last release
Last repo commit
First released
Downloads 179,931/month — #10,159 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_runtime_xfail-1.1.1-py3-none-any.whl

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: TestingTopic :: Utilities

Tags

pytest xfail runtime decisionconditional test failure markingpytest dynamic xfailruntime expected failurepytest fixture xfailconditional xfail pytest
pytest-plugintest-marking

More Utilities packages