python
config_error
ai_generated
true
Ran 0 tests in 0.000s NO TESTS RAN
ID: python/unittest-testcase-no-tests-ran
80%Fix Rate
87%Confidence
0Evidence
2024-05-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
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.
generic中文
unittest 发现零个测试,因为测试方法不以 'test' 开头、TestCase 子类名不以 'Test' 开头,或发现路径/模式指向了错误的目录。
Workarounds
-
95% success
import unittest class TestMath(unittest.TestCase): def test_add(self): self.assertEqual(1 + 1, 2) if __name__ == '__main__': unittest.main() -
90% success
python -m unittest discover -s tests -p 'test_*.py' -v
Dead Ends
Common approaches that don't work:
-
70% fail
More verbose output still reports zero tests; the naming problem is unchanged.
-
60% fail
File naming is necessary but not sufficient; methods must also start with 'test'.