Suppose a test says a function should return two, and the function currently returns one. The assertion describes the behavior you want, the failing run shows a discrepancy, and a separate change will determine how to address it. If the team wants to keep running that test in the meantime, it needs a way to record the known mismatch without treating every run of it as a fresh failure. It also needs to notice when the evidence changes. Otherwise, the test can sit in the suite telling a story that no longer matches what the code does.
In one test-only change, we used pytest's strict expected-failure marker to keep known discrepancies executable. The marker lets an expected failure appear in the test report while the job can still pass. The strict part matters when the assertion succeeds. Pytest labels that an unexpected pass and makes the test run fail. That gives the team a reason to look at the assertion and the marker together. The expectation can stay in the test, and the annotation remains a statement about what the team expects to see while the discrepancy is open.
We checked that distinction locally with a synthetic test in pytest 9.2.0. The assertion always expected the value two. In the first invocation, the fixture supplied one, and the assertion raised an AssertionError. The test was marked as a strict expected failure limited to that exception type. Pytest reported one expected failure and exited zero. The assertion ran and failed, even though the command succeeded. If a status display shows only the exit code, that distinction disappears. The individual outcome tells you the assertion failed in the expected way for this fixture.
In the second invocation, the same assertion received two. This time it passed, and pytest reported XPASS(strict) and exited one. In an ordinary test that successful assertion would be welcome. Here the marker was also a prediction about the outcome. The successful assertion contradicted that prediction. An unexpected pass is a reason to look for the change that made the assertion pass, and to decide whether the expectation belongs in the regular suite. It provides one observed outcome under those test conditions. A change to the fixture or an intermittent result could also account for it.
In the third invocation, the fixture raised ValueError instead of reaching the assertion. Pytest reported a failure and exited one. The exception did not match the type specified by the marker in this synthetic example. That demonstrates a separate choice from strictness. Strictness controls what happens when the test unexpectedly passes. The exception filter limits which failures the runner can classify as expected. Even with that filter, another assertion in the same test could fail with the same exception type. Keeping the test focused on the intended discrepancy makes the resulting label easier to interpret.
A hosted backend job for the original test change also passed and reported expected failures in its suite summary. That aggregate is a different piece of evidence from the three local invocations. It describes the outcomes counted across a job. You need the individual results to tell which test produced which label. The controlled local fixture lets us change one input at a time and see how the marker affects both the per-test result and the process exit code. Neither observation measures how quickly known discrepancies get addressed.
When a strict expected-failure test unexpectedly passes, I would first check whether the intended assertion ran against the inputs that originally exposed the mismatch. A repeat under the same conditions can help distinguish a stable change from an intermittent result. If the intended behavior is now consistently present, removing the marker lets the assertion protect that behavior as an ordinary regression test. If the fixture changed instead, the unexpected pass can prompt a closer look at what the test exercises. The practical value is that the marker gives both outcomes a place in CI: a known failure appears in the report, and an unexpected pass asks for a decision. The decision still belongs to the people reading the test and its evidence.
← All engineering articles