python
config_error
ai_generated
true
Ran 0 tests in 0.000s OK
ID: python/unittest-tests-not-discovered
80%Fix Rate
90%Confidence
0Evidence
2024-01-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
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.
generic中文
unittest 发现没有找到测试,因为模块/类/方法命名不匹配模式(test*.py、TestCase 子类、test_* 方法),或者起始目录错误。
Workarounds
-
95% success
# 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% success
python -m unittest discover -s . -t . -p '*_test.py' -v
Dead Ends
Common approaches that don't work:
-
95% fail
Verbosity shows the same 'Ran 0 tests'; it doesn't fix discovery.
-
60% fail
Different discovery rules; may still collect zero if names are wrong.
-
70% fail
Only affects direct execution, not discovery.