# PermissionError: [Errno 13] Permission denied: '/tmp/pytest-of-root/pytest-0/test_write_file0/output.txt'

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

## Root Cause

A previous pytest run as root created tmp_path directories owned by root under /tmp/pytest-of-<user>/. A subsequent run as a non-root user cannot write into those directories.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   rm -rf /tmp/pytest-of-$(whoami)
# or, if owned by root:
sudo rm -rf /tmp/pytest-of-root
pytest tests/
   ```
2. **** (92% success)
   ```
   pytest --basetemp=/home/$(whoami)/pytest-tmp tests/
# or in pyproject.toml:
# [tool.pytest.ini_options]
# basetemp = "/home/me/pytest-tmp"
   ```

## Dead Ends

- **** — Only fixes this run; the next pytest invocation creates a new numbered directory with the same root ownership problem. (80% fail)
- **** — pytest still uses /tmp/pytest-of-<user>, so the ownership collision persists. (85% fail)
