python
config_error
ai_generated
true
Ran 0 tests in 0.000s NO TESTS RAN FAILED (errors=0)
ID: python/unittest-no-tests-ran
80%Fix Rate
86%Confidence
0Evidence
2024-02-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
unittest discovery found no test methods because the class does not subclass unittest.TestCase, method names do not start with `test`, or the module is not named `test*.py` / the start directory is wrong.
generic中文
unittest 发现机制没有找到任何测试方法,因为类没有继承 unittest.TestCase、方法名不以 `test` 开头,或模块没有命名为 `test*.py` / 起始目录不正确。
Workarounds
-
95% success
Ensure the class inherits TestCase and methods start with test: import unittest class TestMath(unittest.TestCase): def test_add(self): self.assertEqual(1+1, 2) -
90% success
Point discovery at the right start dir and pattern: python -m unittest discover -s tests -p 'test_*.py' -v
Dead Ends
Common approaches that don't work:
-
80% fail
Default discovery pattern is `test*.py`; `tests.py` does not match, so still 0 tests.
-
75% fail
Running via `python -m unittest discover` ignores that block; discovery still finds nothing.