python
system_error
ai_generated
partial
OSError: [Errno 28] No space left on device: '/tmp/pytest-of-runner/pytest-123/test_x0/data.bin'
ID: python/pytest-tmp-path-not-cleaned
80%Fix Rate
82%Confidence
0Evidence
2025-03-25First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Tests write large files into tmp_path, and pytest's tmp_path retention (default 3 runs) plus parallel xdist workers accumulate data faster than it is pruned.
generic中文
测试向 tmp_path 写入大文件,加上 pytest 的 tmp_path 保留策略(默认保留 3 次运行)和并行 xdist worker,数据累积速度快于清理速度。
Workarounds
-
90% success
# pyproject.toml [tool.pytest.ini_options] # pytest keeps last 3 by default; use a fixture to clean large files def test_big(tmp_path): p = tmp_path / 'data.bin' try: p.write_bytes(b'x' * 10_000_000) ... finally: p.unlink(missing_ok=True) -
88% success
# CI step pytest --basetemp=/tmp/pytest-$CI_JOB_ID tests/ rm -rf /tmp/pytest-$CI_JOB_ID # Or in conftest: import shutil, pytest @pytest.fixture(scope='session', autouse=True) def _clean_basetemp(request): yield shutil.rmtree(request.config.option.basetemp, ignore_errors=True)
Dead Ends
Common approaches that don't work:
-
80% fail
Buying time, not fixing the leak; suites that grow will hit the same limit and the cost increases.
-
85% fail
RAM disk is smaller than /tmp; large test artifacts fill it faster and cause OOM or ENOSPC sooner.