python
runtime_error
ai_generated
partial
AssertionError: assert 'foo' == 'bar' # intermittent
ID: python/pytest-flaky-test-random-failure
80%Fix Rate
80%Confidence
0Evidence
2024-12-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Test depends on ordering or shared mutable state; when run in a different order (e.g., with `-p no:randomly` or xdist), it fails.
generic中文
测试依赖于顺序或共享可变状态;当以不同顺序运行(例如使用 `-p no:randomly` 或 xdist)时,它会失败。
Workarounds
-
95% success
@pytest.fixture def state(): return {} def test_a(state): state['x'] = 1 -
85% success
pytest -p randomly --randomly-seed=12345
Dead Ends
Common approaches that don't work:
-
70% fail
Masks the underlying bug and increases test time; failures may still occur.
-
60% fail
Hides the order dependency but does not fix it; CI may use a different order.