# AssertionError: assert 0 == 1
# 使用 -p no:xdist 通过，使用 -n auto 失败

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

## 根因

测试共享全局状态（模块级字典、单例或数据库行），一个测试修改后被另一个测试依赖。pytest-xdist 将测试分发到不同 worker，破坏了隐式顺序。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   @pytest.fixture(autouse=True)
def reset_state():
    mypkg.cache.clear()
    yield
    mypkg.cache.clear()
   ```
2. **** (80% 成功率)
   ```
   pytest -n auto --dist=loadscope
   ```

## 无效尝试

- **** — Hides the underlying state leak and defeats the purpose of using xdist for speed. (70% 失败率)
- **** — Shuffling makes the flakiness worse and harder to reproduce, not better. (80% 失败率)
