Flaky Test Investigator

Likely causes of test flakiness, each with the evidence needed to confirm it.

Advanced · Works with ChatGPT, Claude, Gemini, Copilot

The prompt

Work through the likely causes of this flaky test, in this order: first consider whether the failure symptom might not be the real failure, then list causes with the evidence that would confirm each, then explain the mechanism behind the top cause so this class of bug is recognizable next time, then end with the weakest part of this diagnosis.

Flaky test and failure pattern:
{{CODE}}

Stack and test runner:
{{STACK}}

Why this prompt works

Explaining the mechanism, not just naming the fix, means the next flaky test of this type gets recognized faster.

How to customize it

  • Reproduce the failure locally under the same conditions (parallelism, timing) as CI before trusting a fix.
  • Fix shared-state or ordering issues rather than adding retries to mask them.

Common mistakes

  • Assuming the test itself is at fault when the actual code has a race condition.
  • Adding a sleep() to 'fix' timing issues instead of removing the race.

Example

Input

Flaky test and pattern: test_order_total fails ~1 in 20 runs, only in CI, never locally

What a good answer looks like

A ranked list of causes with confirming evidence, and an explanation of the underlying mechanism.

Make this prompt fit your work

ModelCoach.ai scores your version, shows what to improve and explains why, right inside ChatGPT, Claude, Gemini and Copilot.

Related prompts