A Python automation test is flaky only in CI or under parallel execution. How do you investigate it instead of just adding retries?
Answer
First make the failure observable: preserve traceback, logs, request/response evidence, browser trace or screenshot, test seed and worker identity. Reproduce with the same environment and execution mode, then test the common causes systematically: fixed sleeps, stale or brittle locators, shared state, test-order dependence, data collisions, asynchronous completion and environment instability. Quarantine a known flaky test from a blocking gate if necessary, but keep ownership and a fix deadline; retries may reduce disruption only when they are visible and measured, never as the root-cause strategy.
Strong answer includes
- collects enough CI evidence to reproduce the exact failing conditions
- investigates timing, shared state, ordering, selectors and environment instead of assuming product failure
- treats quarantine or retries as controlled mitigation with ownership, not the fix
Practical example
A checkout test passes locally but fails 3% of the time on four CI workers. The trace shows two workers reuse the same cart account and overwrite each other's state. Creating isolated users removes the flake; adding
reruns=3would only have hidden the race and made the pipeline look healthier than it was.