python
config_error
ai_generated
true
Ran 0 tests in 0.000s NO TESTS RAN
ID: python/unittest-test-discovery-zero-tests
80%Fix Rate
89%Confidence
0Evidence
2024-04-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
unittest discovery requires test files to match `test*.py` and classes to subclass `unittest.TestCase`. Common causes: file named `tests_foo.py`, class not inheriting TestCase, or discovery started from the wrong directory without `-s`.
generic中文
unittest 发现要求测试文件匹配 `test*.py`,且类必须继承 `unittest.TestCase`。常见原因:文件名为 `tests_foo.py`、类未继承 TestCase、或从错误目录启动发现且未使用 `-s`。
Workarounds
-
96% success
# tests/test_math.py import unittest class TestMath(unittest.TestCase): def test_add(self): self.assertEqual(1 + 1, 2) # run python -m unittest discover -s tests -p "test*.py" -v -
93% success
python -m unittest tests.test_math -v # or python -m unittest tests.test_math.TestMath.test_add
Dead Ends
Common approaches that don't work:
-
85% fail
Discovery only collects TestCase subclasses; a plain class with test_ methods is ignored.
-
60% fail
Default start dir is '.', but if tests live in a subdir not on the path, discovery finds nothing.