pytest-dev/pytest · error · UsageError

Config file '{inipath_}' has an unsupported format. Supporte

Error message

Config file '{inipath_}' has an unsupported format. Supported extensions are: {supported}.

What it means

After confirming the -c target is a regular file, pytest looks up a loader by extension (CONFIG_LOADERS_BY_SUFFIX: typically .ini/.toml/.cfg/.txt). If the extension has no registered loader, it raises UsageError listing the supported extensions so the user knows what to rename or convert to.

Source

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

    if inifile:
        inipath_ = absolutepath(inifile)
        if not inipath_.exists():
            raise UsageError(
                f"Config file '{inipath_}' not found. "
                f"Check your '-c/--config-file' option."
            )
        if inipath_.is_dir():
            raise UsageError(
                f"Config file '{inipath_}' is a directory. "
                f"Check your '-c/--config-file' option."
            )
        inipath: Path | None = inipath_
        loader = _get_config_loader(inipath_)
        if loader is not None:
            inicfg = loader(inipath_) or {}
        elif inipath_.is_file():
            supported = ", ".join(sorted(CONFIG_LOADERS_BY_SUFFIX))
            raise UsageError(
                f"Config file '{inipath_}' has an unsupported format. "
                f"Supported extensions are: {supported}."
            )
        else:
            # A file pytest has no loader for is an error, but a path that is
            # not a regular file to begin with cannot hold configuration at
            # all: it is the way to ask for no configuration, as with
            # ``--config-file=/dev/null``.
            inicfg = {}
        if rootdir_cmd_arg is None:
            if inipath_.is_file():
                rootdir = inipath_.parent
            else:
                # Such a path also says nothing about where the project lives,
                # so the rootdir must not be derived from it -- otherwise
                # ``--config-file=/dev/null`` roots at ``/dev`` and the cache
                # plugin warns that it cannot write ``/dev/.pytest_cache``
                # (#11502).

View on GitHub (pinned to 0d6fbdeffa)

Solutions

  1. Rename or convert the file to a supported extension: .ini, .toml, .cfg, or .txt as listed in the message.
  2. If you genuinely want no config from that path, point at /dev/null: pytest -c /dev/null.
  3. Move the settings into a pyproject.toml [tool.pytest.ini_options] table and drop the -c flag.

Example fix

// before
pytest -c config.yaml
// after
pytest -c config.toml   # after converting the file to TOML
Defensive patterns

Strategy: validation

Validate before calling

import pathlib

SUPPORTED = {'.ini', '.toml', '.cfg', '.txt'}

def validate_config_suffix(p: str) -> None:
    suffix = pathlib.Path(p).suffix
    assert suffix in SUPPORTED, f'unsupported config suffix {suffix!r}; use one of {SUPPORTED}'

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: pytest -c config.yaml or config.json; a file with no extension; an unusual extension like .conf not in the supported set.

Common situations: Migrating config to YAML/JSON (unsupported); pointing -c at a random file; renaming pytest.ini to pytest.local.

Related errors


AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11). Data as JSON: /api/errors/d13198cdf41bc51b. Report an issue: GitHub.