pytest-dev/pytest · error · UsageError

plugin {name} cannot be disabled

Error message

plugin {name} cannot be disabled

What it means

Certain pytest plugins are essential for core functionality (mark, main, runner, fixtures, helpconfig) and cannot be disabled with -p no:NAME. Attempting to block one raises UsageError in consider_pluginarg(). Disabling them would break test collection and execution entirely.

Source

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

                        parg = args[i]
                    except IndexError:
                        return
                    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.

View on GitHub (pinned to 98b357f69e)

Solutions

  1. Remove the -p no:<essential_plugin> flag for the blocked plugin.
  2. If you need to change fixture or marker behavior, use the appropriate pytest hooks/options instead of disabling the plugin.
  3. Review the essential_plugins tuple in src/_pytest/config/__init__.py to know which names are off-limits.

Example fix

# before
pytest -p no:fixtures

# after
pytest  # do not disable core fixtures plugin
Defensive patterns

Strategy: validation

Validate before calling

# Essential plugins that cannot be disabled via -p no:NAME
ESSENTIAL_PLUGINS = {'mark', 'main', 'runner', 'fixtures', 'helpconfig'}

def safe_disable_plugin(name: str) -> str:
    if name in ESSENTIAL_PLUGINS:
        raise ValueError(f"Cannot disable essential plugin '{name}'")
    return f'-p no:{name}'

Prevention

When it happens

Trigger: Running pytest with -p no:mark, -p no:fixtures, -p no:runner, -p no:main, or -p no:helpconfig. The name is found in the essential_plugins tuple, so UsageError is raised.

Common situations: Trying to speed up pytest by disabling 'unused' plugins, or cargo-culting -p no:X flags from a config file without understanding which are essential.

Related errors


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