# AssertionError: assert 0 == 3
  # 单独运行时通过，完整套件运行时失败

- **ID:** `python/pytest-test-order-dependency-flaky`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试共享模块级或数据库状态并依赖执行顺序。前面的测试修改了全局状态（例如注册表字典），后续测试假设它是干净的，因此单独运行通过但完整运行失败。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   @pytest.fixture(autouse=True)
def reset_registry():
    registry.clear()
    yield
    registry.clear()
   ```
2. **** (90% 成功率)
   ```
   @pytest.fixture
def app():
    return App()  # fresh per test
   ```

## 无效尝试

- **** — Disabling random ordering makes the order fixed but does not remove the shared-state dependency; it just hides it under one deterministic order. (60% 失败率)
- **** — Reruns may eventually pass but the underlying state leak persists and slows the suite. (70% 失败率)
