python system_error ai_generated true

PermissionError: [Errno 13] 权限被拒绝: '/tmp/pytest-of-user/pytest-123/test_0/'

PermissionError: [Errno 13] Permission denied: '/tmp/pytest-of-user/pytest-123/test_0/'

ID: python/pytest-tmpdir-permission-denied

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-02-05首次发现

版本兼容性

版本状态引入弃用备注
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

根因分析

pytest 的 tmpdir fixture 无法创建或访问临时目录,因为权限不足,通常发生在容器等受限环境中。

English

The pytest tmpdir fixture cannot create or access a temporary directory due to insufficient permissions, often in restricted environments like containers.

generic

解决方案

  1. 90% 成功率
    Set a custom temp directory with write permissions: `pytest --basetemp=/home/user/tmp`
  2. 85% 成功率
    Use the `tmp_path` fixture instead of `tmpdir` (returns pathlib.Path) and ensure the parent directory is writable.

无效尝试

常见但无效的做法:

  1. 80% 失败

    This is a security risk and may not be allowed in containerized environments; also, the issue might be with specific subdirectories.

  2. 90% 失败

    Running tests as root is dangerous and can mask permission issues that would occur in production.