python
config_error
ai_generated
true
在 0.000 秒内运行了 0 个测试 OK
Ran 0 tests in 0.000s OK
ID: python/unittest-tests-not-discovered
80%修复率
90%置信度
0证据数
2024-01-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
unittest 发现没有找到测试,因为模块/类/方法命名不匹配模式(test*.py、TestCase 子类、test_* 方法),或者起始目录错误。
English
unittest discovery found no tests because the module/class/method naming didn't match the pattern (test*.py, TestCase subclass, test_* method), or the start directory was wrong.
解决方案
-
95% 成功率
# tests/test_calc.py import unittest class TestCalc(unittest.TestCase): def test_add(self): self.assertEqual(1+1, 2) # run python -m unittest discover -s tests -p 'test*.py' -v -
90% 成功率
python -m unittest discover -s . -t . -p '*_test.py' -v
无效尝试
常见但无效的做法:
-
95% 失败
Verbosity shows the same 'Ran 0 tests'; it doesn't fix discovery.
-
60% 失败
Different discovery rules; may still collect zero if names are wrong.
-
70% 失败
Only affects direct execution, not discovery.