# pytest.xdist.NoWorkerIdle：没有空闲工作节点可用于测试调度

- **ID:** `python/pytest-xdist-no-worker-idle`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

所有工作进程都在处理长时间运行的测试，并且在超时时间内没有工作节点空闲。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## 解决方案

1. **Reduce the number of workers to match the number of available CPU cores.** (80% 成功率)
   ```
   pytest -n 4 (where 4 is the number of cores)
   ```
2. **Run long-running tests sequentially by marking them with @pytest.mark.slow and using -m 'not slow'.** (85% 成功率)
   ```
   pytest -m 'not slow' -n auto; then run slow tests separately with -n 1
   ```

## 无效尝试

- **Increasing the number of workers to speed up tests** — If tests are long, more workers may not help if the bottleneck is I/O or CPU. (60% 失败率)
- **Setting a global timeout for all tests** — Timeout may abort tests prematurely without addressing the scheduling issue. (70% 失败率)
