python
config_error
ai_generated
true
ERROR: /path/pytest.ini:1: 意外的行: '[tool:pytest]' # 或: pyproject.toml: 未找到 [tool.pytest.ini_options] 段
ERROR: /path/pytest.ini:1: unexpected line: '[tool:pytest]' # or: pyproject.toml: no [tool.pytest.ini_options] section found
ID: python/pytest-config-error-nested-ini
80%修复率
86%置信度
0证据数
2025-03-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
在 pytest.ini 中写入了 [tool:pytest] 段(应使用 [pytest]),或 pyproject.toml 缺少必需的 [tool.pytest.ini_options] 头。
English
The [tool:pytest] section was written in pytest.ini (which expects [pytest]), or the pyproject.toml lacks the required [tool.pytest.ini_options] header.
解决方案
-
98% 成功率
# pytest.ini [pytest] addopts = -ra # pyproject.toml [tool.pytest.ini_options] addopts = '-ra' # setup.cfg [tool:pytest] addopts = -ra
-
90% 成功率
ls pytest.ini tox.ini setup.cfg pyproject.toml # Keep exactly one with the correct section; delete or empty the others.
无效尝试
常见但无效的做法:
-
75% 失败
pytest reads only one config file and ignores the duplicate; the parse error remains or config is silently dropped.
-
60% 失败
setup.cfg expects [tool:pytest] but other tools may also read it; renaming alone does not fix the section header inside.