# PermissionError: [Errno 13] Permission denied: '/tmp/pytest-of-user/pytest-123/test_xxx0/tmp_file.txt'

- **ID:** `python/pytest-tmp-path-permission`
- **Domain:** python
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

测试尝试写入 tmp_path 目录，但该目录权限受限，或测试以非特权用户运行。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.4.0 | active | — | — |
| 8.0.0 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   在测试中打印 tmp_path 并确保目录存在且可写，必要时使用 `tmp_path.mkdir(parents=True, exist_ok=True)`。
   ```
2. **** (85% success)
   ```
   使用 `tmp_path_factory.mktemp('test_dir')` 创建自定义目录，确保权限正确。
   ```

## Dead Ends

- **** — 修改系统目录权限可能影响其他进程，且不安全。 (70% fail)
- **** — 绝对路径可能指向不可写位置，且测试不可移植。 (60% fail)
