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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 98% 成功率
    # pytest.ini
    [pytest]
    addopts = -ra
    
    # pyproject.toml
    [tool.pytest.ini_options]
    addopts = '-ra'
    
    # setup.cfg
    [tool:pytest]
    addopts = -ra
  2. 90% 成功率
    ls pytest.ini tox.ini setup.cfg pyproject.toml
    # Keep exactly one with the correct section; delete or empty the others.

无效尝试

常见但无效的做法:

  1. 75% 失败

    pytest reads only one config file and ignores the duplicate; the parse error remains or config is silently dropped.

  2. 60% 失败

    setup.cfg expects [tool:pytest] but other tools may also read it; renaming alone does not fix the section header inside.