navigation

Carry .testmondata from job to job

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.

Limits

  • The file holds only the last result of each test, as seen by one job.
  • Parallel jobs of one environment (shards, concurrent runs) can’t merge their results. Only one of them can save under a key; with different keys, the next job restores just one of the files.
  • Caches are scoped by branch: a branch restores its own entries, then those of the base and default branch. What a branch or pull request records never reaches the main branch or other branches.
  • When the cache is evicted, the next run runs all tests.

If these cost you more full runs than testmon saves, let testmon.net keep the data.