python config_error ai_generated true

pytest-cache: no previously failed tests found

ID: python/pytest-cache-last-failed

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2025-02-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.0.0 active
8.0.0 active

Root Cause

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.

generic

中文

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

Workarounds

  1. 95% success 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.
  2. 80% success Use --co (cache-show) to inspect the cache contents
    Run: pytest --co
    This shows the cached results. If empty, run the full suite first.

Dead Ends

Common approaches that don't work:

  1. Running pytest --clear-cache to reset the cache 60% fail

    This removes any existing cache, making the situation worse if there was data.

  2. Manually creating a cache file with dummy data 90% fail

    This is error-prone and may cause pytest to misbehave if the format is incorrect.