pytest-dev/pytest · error · UsageError

Blocking conftest files using -p is not supported: -p no

Error message

Blocking conftest files using -p is not supported: -p no:{name}
conftest.py files are not plugins and cannot be disabled via -p.

What it means

Raised by consider_pluginarg() (src/_pytest/config/__init__.py:852-856) when `-p no:<name>` ends with 'conftest.py'. conftest files are not registered as plugins (they are auto-loaded collection hooks), so the disable mechanism does not apply. pytest rejects this with a UsageError explaining the misuse.

Solutions

  1. Rename the conftest.py (e.g. to conftest_disabled.py) or move it out of the collection path if you truly need to skip it
  2. Use --noconftest to skip ALL conftest.py loading (heavy-handed but supported)
  3. Use --confcutdir to bound how deep pytest searches for conftest.py files
  4. Edit the conftest.py to guard its side effects behind a conditional

Example fix

// before
pytest -p no:tests/conftest.py
// after
pytest --noconftest tests/
Defensive patterns

Strategy: validation

Validate before calling

name = arg[3:]  # strip 'no:'
if name.endswith('conftest.py'):
    raise ValueError(f'conftest.py cannot be disabled via -p; use --noconftest')

Type guard

def is_plugin_not_conftest(name: str) -> bool:
    return not name.endswith('conftest.py')

Try / catch

from _pytest.config import UsageError
try:
    pytest.main(['-p', arg])
except UsageError as e:
    print(e)

Prevention

When it happens

Trigger: Invoking `pytest -p no:conftest.py` or `-p no:tests/conftest.py`. The endswith() check at config/__init__.py:852 fires before set_blocked() is reached.

Common situations: Confusion between conftest.py files (which pytest always loads when collecting) and actual plugins (modules registered via entry points or -p). Users sometimes try to silence a noisy conftest by disabling it via -p.

Related errors


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

Appendix: source

Thrown at src/_pytest/config/__init__.py:852

                    i += 1
                elif opt.startswith("-p"):
                    parg = opt[2:]
                else:
                    continue
                parg = parg.strip()
                if exclude_only and not parg.startswith("no:"):
                    continue
                self.consider_pluginarg(parg)

    def consider_pluginarg(self, arg: str) -> None:
        """:meta private:"""
        if arg.startswith("no:"):
            name = arg[3:]
            if name in essential_plugins:
                raise UsageError(f"plugin {name} cannot be disabled")

            if name.endswith("conftest.py"):
                raise UsageError(
                    f"Blocking conftest files using -p is not supported: -p no:{name}\n"
                    "conftest.py files are not plugins and cannot be disabled via -p.\n"
                )

            # PR #4304: remove stepwise if cacheprovider is blocked.
            if name == "cacheprovider":
                self.set_blocked("stepwise")
                self.set_blocked("pytest_stepwise")

            self.set_blocked(name)
            if not name.startswith("pytest_"):
                self.set_blocked("pytest_" + name)
        else:
            name = arg
            # Unblock the plugin.
            self.unblock(name)
            if not name.startswith("pytest_"):
                self.unblock("pytest_" + name)

View on GitHub (pinned to 0d6fbdeffa)