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%修复率
86%置信度
0证据数
2024-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
unittest 发现机制没有找到任何测试方法,因为类没有继承 unittest.TestCase、方法名不以 `test` 开头,或模块没有命名为 `test*.py` / 起始目录不正确。
English
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.
解决方案
-
95% 成功率
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% 成功率
Point discovery at the right start dir and pattern: python -m unittest discover -s tests -p 'test_*.py' -v
无效尝试
常见但无效的做法:
-
80% 失败
Default discovery pattern is `test*.py`; `tests.py` does not match, so still 0 tests.
-
75% 失败
Running via `python -m unittest discover` ignores that block; discovery still finds nothing.