python runtime_error ai_generated partial

AssertionError: assert 'foo' == 'bar' # intermittent

ID: python/pytest-flaky-test-random-failure

Also available as: JSON · Markdown · 中文
80%Fix Rate
80%Confidence
0Evidence
2024-12-03First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    @pytest.fixture
    def state():
        return {}
    
    def test_a(state):
        state['x'] = 1
  2. 85% success
    pytest -p randomly --randomly-seed=12345

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Masks the underlying bug and increases test time; failures may still occur.

  2. 60% fail

    Hides the order dependency but does not fix it; CI may use a different order.