# pytest-cache: 未找到之前失败的测试

- **ID:** `python/pytest-cache-last-failed`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

当使用pytest --lf（上次失败）或--ff（首次失败）时，缓存中没有之前的测试运行数据，通常是因为缓存文件缺失或测试套件之前未运行过。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.0.0 | active | — | — |
| 8.0.0 | active | — | — |

## 解决方案

1. **Run the full test suite first to populate the cache, then use --lf** (95% 成功率)
   ```
   First run: pytest
Then run: pytest --lf
This will re-run only the tests that failed in the previous run.
   ```
2. **Use --co (cache-show) to inspect the cache contents** (80% 成功率)
   ```
   Run: pytest --co
This shows the cached results. If empty, run the full suite first.
   ```

## 无效尝试

- **Running pytest --clear-cache to reset the cache** — This removes any existing cache, making the situation worse if there was data. (60% 失败率)
- **Manually creating a cache file with dummy data** — This is error-prone and may cause pytest to misbehave if the format is incorrect. (90% 失败率)
