python
runtime_error
ai_generated
true
AssertionError: assert 0 == 1 + 其中 0 = len(shared_list)
AssertionError: assert 0 == 1 + where 0 = len(shared_list)
ID: python/pytest-flaky-test-order-dependency
80%修复率
88%置信度
0证据数
2025-08-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
测试依赖于另一个测试修改的状态,而执行顺序发生变化或测试并行运行。
English
The test depends on state modified by another test, and the order of execution changed or tests are run in parallel.
解决方案
-
95% 成功率
@pytest.fixture(autouse=True) def reset_shared_list(): shared_list.clear() yield -
90% 成功率
Replace global variables with fixtures that provide fresh instances per test.
无效尝试
常见但无效的做法:
-
70% 失败
This is fragile and does not fix the underlying state leakage; tests may still fail in isolation.
-
90% 失败
This is unreliable and slows down tests.