python config_error ai_generated true

collected 0 items / 1 error ERROR: found no collectors for /proj/tests/test_math.py::test_add

ID: python/pytest-collection-zero-tests

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

The test file or class does not match pytest's default discovery pattern (test_*.py / *_test.py, Test* class, test_* function), or a syntax/import error prevented collection.

generic

中文

测试文件或类不匹配 pytest 的默认发现模式(test_*.py / *_test.py、Test* 类、test_* 函数),或语法/导入错误阻止了收集。

Workarounds

  1. 95% success
    mv tests/math_test.py tests/test_math.py
    # class CheckMath -> class TestMath
    # def check_add -> def test_add
  2. 90% success
    # pytest.ini
    [pytest]
    python_files = *_test.py test_*.py
    python_classes = Check* Test*
    python_functions = check_* test_*
  3. 88% success
    pytest --collect-only -q -vv tests/test_math.py

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Cache provider has nothing to do with discovery patterns.

  2. 90% fail

    There are no failures; there are no tests collected.

  3. 90% fail

    Coverage plugin doesn't affect collection rules.