## TL;DR
Pytest keeps the last few `tmp_path` runs by default and never cleans older ones, so busy CI runners accumulate gigabytes of numbered temp dirs. Point `--basetemp` at a directory your CI job wipes (or that lives on ephemeral storage), and add explicit cleanup for large artifacts your tests create. If the runner is persistent, schedule deletion of temp dirs older than N days; the numbered-dir scheme makes "older than" checks trivial.

## The query
```text
pytest tmp_path cleanup filling disk in CI: how to fix
```

## Use this when
- CI runners run out of disk during test jobs
- You find thousands of old `pytest-*` temp dirs on a machine
- Large test artifacts (DB dumps, downloads) bloat temp space

## Not for
- How to use `tmp_path` in tests generally
- `tmpdir` vs `tmp_path` API differences
- Out-of-memory (RAM) failures

## Steps
1. Inspect the temp root on the CI runner and measure how much old `pytest-*` dirs consume. Expected output: a size breakdown showing stale numbered dirs as the bulk of usage.
2. Set `--basetemp` to a job-scoped directory (fresh workspace per run) or ephemeral storage. Expected output: each CI job starts with an empty temp root.
3. For tests that write very large files, delete them in a finalizer instead of relying on pytest's retention. Expected output: peak disk usage during the run drops.
4. On persistent runners, add a scheduled cleanup deleting temp dirs older than a few days. Expected output: disk usage stays flat across weeks of runs.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_vBcIFDWBOz4oRl4_0D8GUA
