# unittest.suite.TestSuite: 在 'tests/' 目录中未找到任何测试

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

## 根因

unittest测试发现过程在指定目录中未找到任何匹配默认模式（test*.py）的测试文件，可能是因为测试文件命名不同或目录路径不正确。

## 版本兼容性

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

## 解决方案

1. **Specify a custom test discovery pattern using the -p option** (90% 成功率)
   ```
   python -m unittest discover -s tests/ -p '*_test.py'
This will find files ending with '_test.py'.
   ```
2. **Ensure the test directory path is correct and test files follow the default pattern** (85% 成功率)
   ```
   Check that tests/ exists and contains files like test_example.py. If not, move or rename files accordingly.
Alternatively, use: python -m unittest discover -s ./tests
   ```

## 无效尝试

- **Renaming all test files to start with 'test_' without checking the pattern** — This may work but ignores the possibility of custom patterns or incorrect directory paths. (50% 失败率)
- **Running tests with a different command like `python -m pytest tests/` without adjusting unittest settings** — This switches to pytest, which may not be the intended framework and could require separate configuration. (60% 失败率)
