python
runtime_error
ai_generated
true
pytest.PytestUnraisableExceptionWarning: Exception ignored in: <sqlite3.Connection object>
ID: python/pytest-random-order-fixture-collision
80%Fix Rate
84%Confidence
0Evidence
2025-12-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.15.x | active | — | — | — |
Root Cause
pytest-randomly reorders tests; a fixture that relied on side effects from a previously-run test (implicit ordering) now runs first, leaving resources in an unexpected state and triggering unraisable exceptions at GC.
generic中文
pytest-randomly 重排测试;依赖先前测试副作用的 fixture(隐式顺序)现在最先运行,资源处于意外状态,GC 时触发不可抛出异常。
Workarounds
-
93% success
@pytest.fixture def db(tmp_path): p = tmp_path / 'test.db' conn = sqlite3.connect(p) conn.executescript(SCHEMA) yield conn conn.close() -
85% success
pytest --randomly-seed=last -x -q # Reproduce, then refactor fixtures to remove cross-test state
Dead Ends
Common approaches that don't work:
-
75% fail
Hides the ordering bug; CI with a different seed will still fail, and the fixture remains order-dependent.
-
70% fail
Makes local runs deterministic but the underlying implicit dependency remains; any seed change re-exposes the bug.