pytest-dev/pytest · error · UsageError

Config file '{inipath_}' not found. Check your '-c/--config-

Error message

Config file '{inipath_}' not found. Check your '-c/--config-file' option.

What it means

When -c/--config-file is given, pytest resolves the path to an absolute path and verifies existence. If the file does not exist, it raises UsageError naming the path and pointing at the -c option. This fails fast rather than silently searching for config elsewhere.

Source

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

    :param override_ini:
        The -o/--override-ini command line arguments, if given.
    :param args:
        The free command line arguments.
    :param rootdir_cmd_arg:
        The `--rootdir` command line argument, if given.
    :param invocation_dir:
        The working directory when pytest was invoked.

    :raises UsageError:
    """
    rootdir = None
    dirs = get_dirs_from_args(args)
    ignored_config_files: Sequence[str] = []

    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}."
            )

View on GitHub (pinned to 0d6fbdeffa)

Solutions

  1. Verify the file exists from the directory where pytest runs: ls -la <path>.
  2. Use an absolute path or a path relative to the invocation dir that you have confirmed.
  3. If you want no config, point at /dev/null (--config-file=/dev/null) instead of a missing file.

Example fix

// before
pytest -c config/pytest.ini
// after
pytest -c $(pwd)/config/pytest.ini   # after confirming the file is present
Defensive patterns

Strategy: validation

Validate before calling

import os, pathlib

def validate_config_file(p: str) -> None:
    ap = pathlib.Path(os.path.abspath(p))
    assert ap.is_file(), f'config file not found: {ap}'

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: pytest -c pytest-ci.ini where that file was never created; relative path resolved against an unexpected cwd; typo in the filename; CI checked out a branch missing the config file.

Common situations: Wrong working directory in CI; renamed config file but not the -c argument; missing config in a fresh shallow clone.

Related errors


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