pytest-dev/pytest · error · UsageError

Config file '{inipath_}' is a directory. Check your '-c/--co

Error message

Config file '{inipath_}' is a directory. Check your '-c/--config-file' option.

What it means

pytest explicitly checks is_dir() on the -c/--config-file target and rejects directories. A config file must be a regular file so pytest can pick a loader by extension. The error redirects the user to check the -c option.

Source

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

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

View on GitHub (pinned to 0d6fbdeffa)

Solutions

  1. Point -c at a specific config file inside the directory, e.g. pytest -c tests/pytest.ini.
  2. If you meant to set the root, use --rootdir=<dir> instead.
  3. If you want no config, use --config-file=/dev/null.

Example fix

// before
pytest -c tests/
// after
pytest -c tests/pytest.ini
# or
pytest --rootdir=tests/
Defensive patterns

Strategy: validation

Validate before calling

import os, pathlib

def validate_config_not_dir(p: str) -> None:
    ap = pathlib.Path(os.path.abspath(p))
    assert not ap.is_dir(), f'-c target is a directory: {ap}; pass a file path'

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Passing a directory path to -c (pytest -c tests/); a glob expanding to a directory; copying a command from docs that used a dir placeholder.

Common situations: Confusing --rootdir (a directory) with -c (a file); pointing -c at a conftest directory.

Related errors


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