pytest-dev/pytest · error · UsageError

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

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

conftest.py files are loaded by pytest's collection mechanism, not the plugin system, so they cannot be blocked with -p no:. If the name passed to -p no: ends with 'conftest.py', pytest raises UsageError explaining the distinction. This prevents users from misunderstanding the plugin architecture.

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 98b357f69e)

Solutions

  1. Use --noconftest to prevent conftest.py files from being loaded.
  2. Move or rename the conftest.py if it should not apply to the current run.
  3. Use -p no:<plugin_name> only for actual plugins, not conftest.py files.

Example fix

# before
pytest -p no:tests/conftest.py

# after
pytest --noconftest
Defensive patterns

Strategy: validation

Validate before calling

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

# Do not attempt -p no:<name> if is_conftest_name(name); use --noconftest instead.

Prevention

When it happens

Trigger: Running pytest with a flag like -p no:conftest.py or -p no:tests/conftest.py. The name.endswith('conftest.py') check is True, so UsageError is raised.

Common situations: Users trying to suppress a conftest.py that interferes with a test run, or misunderstanding -p no: as a general file-blocking mechanism.

Related errors


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