python
system_error
ai_generated
true
PermissionError: [Errno 13] Permission denied: '/tmp/pytest-of-root/pytest-0/test_x0/out.txt'
ID: python/pytest-tmp-path-permissions
80%Fix Rate
85%Confidence
0Evidence
2024-11-04First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Tests run as root in one environment left /tmp/pytest-of-root owned by root; subsequent runs as a different user cannot write into the same tmp_path base.
generic中文
在一个环境中以 root 运行的测试留下了由 root 拥有的 /tmp/pytest-of-root;随后以其他用户运行无法写入同一个 tmp_path 基础目录。
Workarounds
-
95% success
# pytest.ini [pytest] addopts = --basetemp=/home/ci/pytest-tmp # ensure /home/ci/pytest-tmp exists and is writable
-
90% success
sudo rm -rf /tmp/pytest-of-root pytest tests/
Dead Ends
Common approaches that don't work:
-
70% fail
Security risk and the next root run recreates restrictive perms.
-
60% fail
May still collide if /var/tmp/pytest-of-root exists from a root run.
-
75% fail
Loses pytest cleanup guarantees and can leave garbage.