# FileNotFoundError: [Errno 2] 没有那个文件或目录: 'test_data.csv'

- **ID:** `python/unittest-testloader-filenotfounderror`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

一个 unittest TestCase 尝试使用相对路径加载数据文件，但当前工作目录不是测试数据目录。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Use an absolute path derived from the test file location: `import os; data_path = os.path.join(os.path.dirname(__file__), 'test_data.csv')`
   ```
2. **** (90% 成功率)
   ```
   Place test data in a fixed directory and configure the test runner to always start from the project root.
   ```

## 无效尝试

- **** — This is inefficient and clutters the project; the file might still be missed if the path resolution is inconsistent. (80% 失败率)
- **** — This can affect other tests running in parallel and cause race conditions or side effects. (70% 失败率)
