python
config_error
ai_generated
true
0.00s 内没有运行任何测试 ERROR: 找不到文件或目录:tests/
no tests ran in 0.00s ERROR: file or directory not found: tests/
ID: python/pytest-exit-code-no-tests-collected
80%修复率
90%置信度
0证据数
2024-12-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
传给 pytest 的路径相对于当前工作目录不存在。常发生在 CI 中:工作目录是仓库根,但测试位于子包中,或者 Makefile 切换了目录。
English
The path passed to pytest does not exist relative to the current working directory. Often happens in CI when the working directory is the repo root but tests live in a sub-package, or when a Makefile changes directory.
解决方案
-
95% 成功率
Verify the path and use the full path: pytest ./backend/tests
-
95% 成功率
Set testpaths in config so pytest finds the right directory regardless of cwd: # pyproject.toml [tool.pytest.ini_options] testpaths = ["backend/tests"]
无效尝试
常见但无效的做法:
-
50% 失败
May collect unrelated tests or fail to find anything if rootdir is misconfigured.
-
90% 失败
Silences the error but runs zero tests, causing CI to pass green with no coverage.