# 值错误：未收集到任何测试。确保测试文件以 'test_' 开头或以 '_test.py' 结尾。

- **ID:** `python/valueerror-no-tests-collected`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Pytest 或 unittest 找不到测试文件，因为它们不符合默认命名约定。

## 版本兼容性

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

## 解决方案

1. **Rename test files to match pattern** (95% 成功率)
   ```
   mv my_tests.py test_my_tests.py
   ```
2. **Use pytest --collect-only to debug discovery** (90% 成功率)
   ```
   pytest --collect-only -v
   ```

## 无效尝试

- **Creating test files with arbitrary names** — Pytest only discovers files matching patterns like test_*.py or *_test.py. (80% 失败率)
- **Running pytest from wrong directory** — If tests are in a subdirectory, pytest must be run from the root or with --rootdir. (60% 失败率)
