python
runtime_error
ai_generated
partial
检测到不稳定的测试: test_foo 失败 2 次,通过 1 次
Flaky test detected: test_foo failed 2 times, passed 1 time
ID: python/pytest-flaky-test-rerun-failed
80%修复率
80%置信度
0证据数
2024-08-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.2 | active | — | — | — |
根因分析
测试不稳定,意味着由于非确定性行为、竞争条件或外部依赖,它有时通过有时失败。
English
The test is flaky, meaning it sometimes passes and sometimes fails due to non-deterministic behavior, race conditions, or external dependencies.
解决方案
-
85% 成功率
Look for: random data, time-dependent logic, network calls, shared state, order dependence. Use pytest -p no:randomly to disable random order.
-
90% 成功率
For random: random.seed(42) For time: freeze_time or mock datetime.now() For network: use responses or mock.
无效尝试
常见但无效的做法:
-
90% 失败
This masks the flakiness and can hide real bugs.
-
80% 失败
This stops the test from running and doesn't fix the underlying issue.