Complete worked example
python
import pytest
def legacy_decode(value):
return value
def current_decode(value):
return value.upper()
@pytest.mark.xfail(strict=True, raises=AssertionError, reason="Owned teaching defect: legacy decoder omits uppercase")
def test_known_legacy_defect():
assert legacy_decode("sql") == "SQL"
def test_current_decoder():
assert current_decode("sql") == "SQL"- Reasoning
- The worked example includes a deliberately broken legacy decoder with a strict expected-failure test. The test still runs, fails and is reported as xfailed. A separate current decoder is tested normally. strict=True makes an unexpected pass fail the session so the known-defect marker must be reviewed. The raises argument narrows the expected failure type to AssertionError in this example. It prevents an unrelated error type from satisfying the marker. It does not prove that the precise assertion failed for the intended underlying reason; keep the test body small and specific.