python config_error ai_generated true

Ran 0 tests in 0.000s(未运行任何测试)

Ran 0 tests in 0.000s

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

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2024-02-27首次发现

版本兼容性

版本状态引入弃用备注
3.10 active — — —
3.12 active — — —

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 85% 失败

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

  2. 60% 失败

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