# pytest.PytestUnraisableExceptionWarning: 忽略异常: <sqlite3.Connection 对象>

- **ID:** `python/pytest-random-order-fixture-collision`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest-randomly 重排测试；依赖先前测试副作用的 fixture（隐式顺序）现在最先运行，资源处于意外状态，GC 时触发不可抛出异常。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.15.x | active | — | — |

## 解决方案

1. **** (93% 成功率)
   ```
   @pytest.fixture
def db(tmp_path):
    p = tmp_path / 'test.db'
    conn = sqlite3.connect(p)
    conn.executescript(SCHEMA)
    yield conn
    conn.close()
   ```
2. **** (85% 成功率)
   ```
   pytest --randomly-seed=last -x -q
# Reproduce, then refactor fixtures to remove cross-test state
   ```

## 无效尝试

- **** — Hides the ordering bug; CI with a different seed will still fail, and the fixture remains order-dependent. (75% 失败率)
- **** — Makes local runs deterministic but the underlying implicit dependency remains; any seed change re-exposes the bug. (70% 失败率)
