python config_error ai_generated true

Ran 0 tests in 0.000s

ID: python/unittest-discovery-no-tests-ran

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-02-27First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.10 active — — —
3.12 active — — —

Root Cause

unittest discover found no test modules because the pattern didn't match, the start directory wasn't a package (missing __init__.py in older versions), or filenames don't match test*.py.

generic

中文

unittest discover 未找到测试模块:匹配模式不符、起始目录不是包(旧版本缺少 __init__.py),或文件名不符合 test*.py。

Workarounds

  1. 92% success
    python -m unittest discover -s tests -p 'test_*.py' -v
    # Ensure tests/ has __init__.py if using package-relative imports
  2. 88% success
    git mv tests/foo_tests.py tests/test_foo.py
    python -m unittest discover -v

Dead Ends

Common approaches that don't work:

  1. 85% fail

    The methods are never executed because discovery fails before collection; prints never run.

  2. 60% fail

    Default pattern is 'test*.py' (prefix). 'mytest.py' won't match; only 'test_*.py' or 'test*.py' work.