pytest-dev/pytest · error · TypeError

help argument cannot be None for {name}

Error message

help argument cannot be None for {name}

What it means

Raised while rendering `pytest --help`/config help (in `showhelp`) for an ini option whose `help` text is None. Every ini option registered via `parser.addini(name, help=...)` must carry a help string; a None help makes the help formatter unable to render the option, so pytest raises TypeError naming the offending option.

Source

Thrown at src/_pytest/helpconfig.py:203

        "terminalreporter"
    )
    assert reporter is not None
    tw = reporter._tw
    tw.write(config._parser.optparser.format_help())
    tw.line()
    tw.line(
        "[pytest] configuration options in the first "
        "pytest.toml|pytest.ini|tox.ini|setup.cfg|pyproject.toml file found:"
    )
    tw.line()

    columns = tw.fullwidth  # costly call
    indent_len = 24  # based on argparse's max_help_position=24
    indent = " " * indent_len
    for name in config._parser._inidict:
        help, type, _default = config._parser._inidict[name]
        if help is None:
            raise TypeError(f"help argument cannot be None for {name}")
        spec = f"{name} ({_ini_type_repr(type)}):"
        tw.write(f"  {spec}")
        spec_len = len(spec)
        if spec_len > (indent_len - 3):
            # Display help starting at a new line.
            tw.line()
            helplines = textwrap.wrap(
                help,
                columns,
                initial_indent=indent,
                subsequent_indent=indent,
                break_on_hyphens=False,
            )

            for line in helplines:
                tw.line(line)
        else:
            # Display help starting after the spec, following lines indented.

View on GitHub (pinned to 98b357f69e)

Solutions

  1. Pass a non-None help string to addini: `parser.addini("my_opt", help="Description here", default=...)`.
  2. Update the offending plugin to the latest version where help text was added.
  3. If you control the conftest, audit every `addini` call for a help argument.

Example fix

// before
def pytest_addoption(parser):
    parser.addini("my_opt", default="x")  # help=None
// after
def pytest_addoption(parser):
    parser.addini("my_opt", help="Controls my thing", default="x")
Defensive patterns

Strategy: validation

Validate before calling

def safe_addini(parser, name, help=None, **kw):
    if help is None:
        raise TypeError(f"help argument cannot be None for {name}")
    parser.addini(name, help=help, **kw)

Prevention

When it happens

Trigger: A plugin/conftest calls `parser.addini("my_opt", default=..., help=None)` or omits help, and the user runs `pytest --help`. The error names the option key.

Common situations: Plugin authors forgetting the help argument. Third-party plugins with incomplete addini calls. A conftest.py registering a custom ini key for project config.

Related errors


AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04). Data as JSON: /data/errors/f03b17a0ba21d2a1.json. Report an issue: GitHub.