pytest-dev/pytest · error · UsageError

-o/--override-ini expects option=value style (got: {ini_conf

Error message

-o/--override-ini expects option=value style (got: {ini_config!r}).

What it means

Raised when a -o/--override-ini command-line argument does not contain an '=' sign separating the option name from its value. pytest splits each override on the first '='; a missing '=' causes str.split('=', 1) to yield a single element, triggering ValueError and this UsageError.

Source

Thrown at src/_pytest/config/findpaths.py:275

    return [get_dir_from_path(path) for path in possible_paths if safe_exists(path)]


def parse_override_ini(override_ini: Sequence[str] | None) -> ConfigDict:
    """Parse the -o/--override-ini command line arguments and return the overrides.

    :raises UsageError:
        If one of the values is malformed.
    """
    overrides = {}
    # override_ini is a list of "ini=value" options.
    # Always use the last item if multiple values are set for same ini-name,
    # e.g. -o foo=bar1 -o foo=bar2 will set foo to bar2.
    for ini_config in override_ini or ():
        try:
            key, user_ini_value = ini_config.split("=", 1)
        except ValueError as e:
            raise UsageError(
                f"-o/--override-ini expects option=value style (got: {ini_config!r})."
            ) from e
        else:
            overrides[key] = ConfigValue(user_ini_value, origin="override", mode="ini")
    return overrides


CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."


def determine_setup(
    *,
    inifile: str | None,
    override_ini: Sequence[str] | None,
    args: Sequence[str],
    rootdir_cmd_arg: str | None,
    invocation_dir: Path,
) -> tuple[Path, Path | None, ConfigDict, Sequence[str]]:

View on GitHub (pinned to 98b357f69e)

Solutions

  1. Always use the form -o name=value, e.g. -o addopts='-v' or -o verbose=true.
  2. For booleans use explicit values: -o verbose=true / verbose=false.
  3. Quote the whole override in the shell if the value contains spaces: -o 'addopts=-v -ra'.

Example fix

# before
pytest -o verbose

# after
pytest -o verbose=true
Defensive patterns

Strategy: validation

Validate before calling

def validate_override(arg: str) -> tuple[str, str]:
    if '=' not in arg:
        raise ValueError(f'-o/--override-ini expects option=value style (got: {arg!r})')
    key, value = arg.split('=', 1)
    if not key:
        raise ValueError(f'empty option name in override {arg!r}')
    return key, value

Type guard

def is_valid_override(arg: str) -> bool:
    return '=' in arg and arg.split('=', 1)[0] != ''

Prevention

When it happens

Trigger: Running pytest -o foo (no value), pytest -o 'justakey', or pytest --override-ini 'verbose' without '=true'. The split at line 273 returns a list of length 1, ValueError is raised and caught at 274-277.

Common situations: Forgetting the '=value' portion of an override; passing a flag-style option name expecting boolean toggling; shell quoting issues that strip the '='; typos in scripted pytest invocations.

Related errors


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