Restore .testmondata before the tests and save it after them, also when the
tests fail. With the GitHub Actions cache:
- uses: actions/cache/restore@v4
id: testmon-restore
with:
path: .testmondata
key: testmon-${{ runner.os }}-py${{ matrix.python }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: testmon-${{ runner.os }}-py${{ matrix.python }}-
- run: pytest --testmon
- uses: actions/cache/save@v4
if: always()
with:
path: .testmondata
key: ${{ steps.testmon-restore.outputs.cache-primary-key }}
Use separate restore and save steps. The combined actions/cache step saves
only when the job succeeds, so after a failed run the next job starts from
older data and runs again what the failed run already learned.
A cache entry can’t be overwritten, so the key contains the run id and attempt:
each run saves a new entry, and restore-keys restores the newest one. Keep one
key prefix per environment (operating system, Python version); data of one
environment is not valid for another. Other CI systems have similar caches or
artifacts.
If these cost you more full runs than testmon saves, let testmon.net keep the data.