When Your Test Suite Catches a Bug Nobody Wanted to Fix
Mature suites have a particular kind of frustration. A test goes red, someone looks, shrugs, and the team moves on. The bug is real and the test is right, but there's a tight sprint, a priority dispute or a "we'll fix it later." The test stays red, people stop looking at the CI dashboard, and the suite loses the trust that makes it worth running.
I've seen this on teams that otherwise did everything right: good coverage, clean scenarios, solid CI. The tests weren't the problem. The problem was the unclear agreement about what a failing test means. When that's fuzzy, a red build stops being a signal.
There's now a quieter version of the same problem. Ask a coding agent to get the pipeline green and an inconvenient failure can disappear: a skip marker, a loosened assertion, an xfail with a vague reason. The bug is just as real and even less visible. This article covers how to record a deferral explicitly, how to make failures impossible to misread, how to keep deferrals from becoming permanent, and how to stop agents from making the decision for you.
Learn Node.js, Cucumber, GitHub Copilot, APIs, CI/CD, and modern automation by building a complete framework.
Make "known failing" an explicit decision
A failing test left without a decision makes everyone who runs the build ask the same question: is this the known failure or a new one? After a while they stop asking, assume red is normal, and new failures go unnoticed.
The fix isn't deleting the test or pretending the bug isn't there. It's recording the decision in code. In pytest that's xfail with a reason and strict=True:
import pytest
@pytest.mark.xfail(
reason="Order status lags payment confirmation - ticket ORD-4821",
strict=True,
)
def test_order_status_reflects_payment_immediately(api_client, paid_order):
response = api_client.get(f"/orders/{paid_order}/status")
assert response.json()["status"] == "paid"
With strict=True, an unexpected pass fails the run. If someone fixes the bug without removing the marker, the suite tells you, so the ticket gets closed and the test goes back to guarding the behaviour. Without strict, a surprise pass shows up as a quiet XPASS that nobody reads.
In Behave, a tag such as @known_issue on the scenario plus a tag filter in the CI job does the same. The point is that the deferral lives in version control, where it's reviewed and searchable, not in a chat message or someone's memory.
Make the failure too clear to ignore
Sometimes nobody decided to defer. The failure just wasn't clear enough to force a decision. AssertionError: assert 404 == 200 is easy to dismiss. A message that names the business behaviour, the evidence and where to look isn't:
def test_discount_code_reduces_cart_total(api_client, cart_with_two_items):
api_client.post(f"/carts/{cart_with_two_items}/discounts", json={"code": "SAVE10"})
cart = api_client.get(f"/carts/{cart_with_two_items}").json()
assert cart["total"] == pytest.approx(cart["subtotal"] * 0.9), (
"Discount SAVE10 was not applied to the cart total. "
f"subtotal={cart['subtotal']} total={cart['total']} "
f"discounts={cart.get('discounts')}. Checkout charges the full price."
)
Nobody can read that in a CI log and say they don't know what it means, which is the excuse that lets failures sit. Turning a failing test run into a useful bug report goes further into what to include.
Routing matters too. A generic "build failed" message in a team channel is everyone's problem and so nobody's. Sending failures to an owner, by test path, marker or service, puts the responsibility somewhere specific. Organizing API test failures so patterns surface fast covers grouping them so the right person sees them. If the same suite runs in several environments, keep each environment's failures separate so a staging-only bug keeps that context.
Give every deferral an expiry date
Deferring a fix is sometimes the right call. The danger is a deferral that never ends. I give each one a review date by making the xfail conditional:
from datetime import date
import pytest
REVIEW_BY = date(2027, 1, 15)
@pytest.mark.xfail(
date.today() < REVIEW_BY,
reason=f"Ticket ORD-4821: deferred until {REVIEW_BY}, then this test fails again",
strict=True,
)
def test_order_status_reflects_payment_immediately(api_client, paid_order):
...
Until the review date, the failure is expected. After it, the condition is false, the marker no longer applies, and the build goes red if the bug is still there. That doesn't fix anything, but it turns "later" into a date the team agreed on. The ticket in the reason string lets anyone who hits the failure find the context.
Be deliberate about what can be deferred at all. A formatting issue in a response is a different risk from a data integrity bug in a write endpoint or a wrong charge at checkout. Some failures should block a release, full stop. Then audit your xfail and skip markers on a regular schedule against your issue tracker. Markers outlive their bugs, and a stale one hides coverage you think you have.
Don't let an agent make the call
When a coding agent is told to fix a failing pipeline, the quickest path to green is often to change the test, not the code. That's the same "we'll ignore it" decision, made silently by a tool. I close that path in two places.
First, the repository instruction file your agent reads, such as .github/copilot-instructions.md:
## Failing tests
- Never add skip, skipif or xfail markers, and never loosen or remove an
assertion, to make a test pass.
- If a test fails because of an application bug, stop and report: the test,
the failure output, and why you believe the application is wrong.
- Deferring a known bug is a human decision recorded with xfail(strict=True),
a ticket ID and a review date.
Second, review. Any diff that adds a skip or xfail marker, or changes a line starting with assert, gets read line by line whoever wrote it. A simple CI check that flags new markers in a pull request makes this hard to miss.
Used this way, an agent is helpful here. It's good at writing up the clear failure report a deferral needs, and at auditing old markers against closed tickets. It just doesn't get to decide that a real bug can wait.
A suite is only as trustworthy as the decisions recorded in it, and those decisions need upkeep like the tests do. If you want to build a suite where failures are clear and deferrals are explicit, with Copilot working inside those rules, my API testing courses walk through it.