Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 1 min read

Freeze Flaky Tests Before You Grade an Agent Patch

A pricing patch arrives with a green CI run and two newly skipped tests. The green result leaves an unanswered question: did the patch improve behavior or simply stop checking it? Freeze the evidence from its base commit

A pricing patch arrives with a green CI run and two newly skipped tests. The green result leaves an unanswered question: did the patch improve behavior or simply stop checking it? Freeze the evidence from its base commit before comparing the candidate.

Record the baseline

Collect test IDs, skip and expected-failure markers, runner configuration and base revision. Repeat the suite in fresh processes under the same recorded conditions. Store each outcome and distinguish an assertion failure from a setup error, missing result or skipped run. Mixed pass/fail outcomes identify observed flakiness. Ten independent runs can easily miss a rare failure. Fresh processes reset process-local state but cannot reset a shared database or an external service.

For the candidate, compare ordinary failures, errors, collection changes, added skips and unexpected changes in outcomes. Treat a red deterministic result as a failure even when it never flips. Require an explanation when a test disappears or becomes skipped. An intermittent failure first observed on the candidate is a reason to investigate. It does not assign causality to the patch on its own.

Test the comparison without waiting for randomness

Feed the comparator fixed histories. For a base history of pass/fail/pass, a candidate history of skip/skip/skip should flag the new skip. For a base history of pass/pass/pass, a candidate of fail/fail/fail must flag the regression, and pass/fail/pass must flag newly observed variation. A formerly intermittent test passing three times is consistent with improvement but cannot prove a cure.

Use these fixtures to verify the reporting code, then repeat real candidate runs to collect evidence. Dictionary iteration in current Python preserves insertion order, so a dictionary populated in the same order is a poor source of deliberately intermittent tests. Fixed histories also make the failure cases reproducible on every runner.

Python mapping types

This article was created with AI assistance.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.