python config_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2025-03-10First Seen

Version Compatibility

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

Root Cause

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

中文

在 pytest.ini 中写入了 [tool:pytest] 段(应使用 [pytest]),或 pyproject.toml 缺少必需的 [tool.pytest.ini_options] 头。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 75% fail

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

  2. 60% fail

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