python config_error ai_generated true

no tests ran in 0.12s ERROR: 文件或目录未找到: tests/test_api.py

no tests ran in 0.12s ERROR: file or directory not found: tests/test_api.py

ID: python/pytest-exit-code-5-no-tests-collected

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

版本兼容性

版本状态引入弃用备注
7.x active — — —
8.x active — — —

根因分析

传给 pytest 的路径相对于当前工作目录不存在,或测试文件被重命名/移动。当未收集到测试时,pytest 以代码 5(EXIT_NOTESTSCOLLECTED)退出。

English

The path passed to pytest does not exist relative to the current working directory, or the test file was renamed/moved. pytest exits with code 5 (EXIT_NOTESTSCOLLECTED) when no tests are collected.

generic

解决方案

  1. 92% 成功率
    cd /app && pytest
  2. 88% 成功率
    test -f tests/test_api.py && pytest tests/test_api.py || echo 'missing test file'

无效尝试

常见但无效的做法:

  1. 90% 失败

    Ignoring the directory means the intended tests never run; the CI job passes green while testing nothing.

  2. 85% 失败

    Masks genuinely missing tests and broken collection, allowing regressions through.