# FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-user/pytest-0/test_foo0/somefile.txt'

- **ID:** `python/pytest-tmpdir-file-not-created`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

在测试中使用 tmpdir fixture 但未先创建文件，直接尝试读取或写入不存在的路径。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |

## Workarounds

1. **使用 tmpdir.join 自动创建** (95% success)
   ```
   file_path = tmpdir.join('file.txt')
file_path.write('content')
   ```
2. **手动创建目录** (85% success)
   ```
   import os
os.makedirs(tmpdir, exist_ok=True)
with open(os.path.join(tmpdir, 'file.txt'), 'w') as f: f.write('x')
   ```

## Dead Ends

- **只创建目录不创建文件** — 尝试使用 tmpdir.mkdir() 创建目录但忘记创建文件 (60% fail)
- **open('subdir/file.txt', 'w')** — 尝试使用 open() 写入但文件路径包含子目录且未创建 (70% fail)
