python
config_error
ai_generated
true
Ran 0 tests in 0.000s NO TESTS RAN
ID: python/unittest-testcase-no-tests-ran
80%修复率
87%置信度
0证据数
2024-05-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
unittest 发现零个测试,因为测试方法不以 'test' 开头、TestCase 子类名不以 'Test' 开头,或发现路径/模式指向了错误的目录。
English
unittest discovers zero tests because test methods do not start with 'test', the TestCase subclass name does not start with 'Test', or discovery was pointed at the wrong directory/pattern.
解决方案
-
95% 成功率
import unittest class TestMath(unittest.TestCase): def test_add(self): self.assertEqual(1 + 1, 2) if __name__ == '__main__': unittest.main() -
90% 成功率
python -m unittest discover -s tests -p 'test_*.py' -v
无效尝试
常见但无效的做法:
-
70% 失败
More verbose output still reports zero tests; the naming problem is unchanged.
-
60% 失败
File naming is necessary but not sufficient; methods must also start with 'test'.