python runtime_error ai_generated true

AssertionError: assert 0 == 1 + where 0 = len(shared_list)

ID: python/pytest-flaky-test-order-dependency

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2025-08-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

The test depends on state modified by another test, and the order of execution changed or tests are run in parallel.

generic

中文

测试依赖于另一个测试修改的状态,而执行顺序发生变化或测试并行运行。

Workarounds

  1. 95% success
    @pytest.fixture(autouse=True)
    def reset_shared_list():
        shared_list.clear()
        yield
  2. 90% success
    Replace global variables with fixtures that provide fresh instances per test.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    This is fragile and does not fix the underlying state leakage; tests may still fail in isolation.

  2. 90% fail

    This is unreliable and slows down tests.