python
config_error
ai_generated
true
运行了 0 个测试,耗时 0.000 秒 未运行任何测试
Ran 0 tests in 0.000s NO TESTS RAN
ID: python/unittest-test-discovery-failure
80%修复率
88%置信度
0证据数
2025-05-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
unittest 未发现任何测试,通常是因为测试文件未命名为 test_*.py 或测试类未继承自 unittest.TestCase。
English
unittest did not discover any tests, often because the test files are not named test_*.py or the test classes do not inherit from unittest.TestCase.
解决方案
-
95% 成功率
Rename files to test_*.py and make test classes subclass unittest.TestCase. Use python -m unittest discover -s tests -p 'test_*.py'
-
90% 成功率
python -m unittest tests.test_module
无效尝试
常见但无效的做法:
-
95% 失败
unittest discovery relies on the test_*.py pattern; renaming may break discovery further.
-
80% 失败
This may run tests if the file has a if __name__ == '__main__' block, but does not fix discovery for all tests.