python
config_error
ai_generated
true
pytest-cache: 未找到之前失败的测试
pytest-cache: no previously failed tests found
ID: python/pytest-cache-last-failed
80%修复率
83%置信度
0证据数
2025-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.0.0 | active | — | — | — |
| 8.0.0 | active | — | — | — |
根因分析
当使用pytest --lf(上次失败)或--ff(首次失败)时,缓存中没有之前的测试运行数据,通常是因为缓存文件缺失或测试套件之前未运行过。
English
When using pytest --lf (last failed) or --ff (first failed), no previous test run data is available in the cache, often because the cache file is missing or the test suite has not been run before.
解决方案
-
95% 成功率 Run the full test suite first to populate the cache, then use --lf
First run: pytest Then run: pytest --lf This will re-run only the tests that failed in the previous run.
-
80% 成功率 Use --co (cache-show) to inspect the cache contents
Run: pytest --co This shows the cached results. If empty, run the full suite first.
无效尝试
常见但无效的做法:
-
Running pytest --clear-cache to reset the cache
60% 失败
This removes any existing cache, making the situation worse if there was data.
-
Manually creating a cache file with dummy data
90% 失败
This is error-prone and may cause pytest to misbehave if the format is incorrect.