Skip to content

defect-xfail-requires-explicit-strict

A deterministic known-defect xfail must set literal strict=True so XPASS fails the suite.

Why

A defect pin that relies on pytest's configurable strictness default can stay green after the defect is fixed, leaving stale coverage and markers behind. Literal local strictness keeps the invariant attached to the pin independently of repository configuration.

Fix

Set literal strict=True so an unexpected pass fails. If only some parameter cases carry the defect, move the marker to those pytest.param(...) cases before making it strict.

Examples

Before — flagged Unexpected pass does not fail the suite
tests/test_api.py
import pytest
@pytest.mark.xfail(reason="BUG: wrong status code")
def test_status():
assert response_status() == 200
After — preferred Unexpected pass fails the suite
tests/test_api.py
import pytest
@pytest.mark.xfail(reason="BUG: wrong status code", strict=True)
def test_status():
assert response_status() == 200

Formerly: defect-xfail-requires-strict, xfail-requires-strict