python
system_error
ai_generated
partial
OSError: [Errno 28] 设备上没有剩余空间: '/tmp/pytest-of-runner/pytest-123/test_x0/data.bin'
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%修复率
82%置信度
0证据数
2025-03-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
测试向 tmp_path 写入大文件,加上 pytest 的 tmp_path 保留策略(默认保留 3 次运行)和并行 xdist worker,数据累积速度快于清理速度。
English
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.
解决方案
-
90% 成功率
# 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% 成功率
# 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)
无效尝试
常见但无效的做法:
-
80% 失败
Buying time, not fixing the leak; suites that grow will hit the same limit and the cost increases.
-
85% 失败
RAM disk is smaller than /tmp; large test artifacts fill it faster and cause OOM or ENOSPC sooner.