{"record":{"id":"2779d1008d3e3d88","repo":"pytest-dev/pytest","slug":"plugin-name-cannot-be-disabled","errorCode":null,"errorMessage":"plugin {name} cannot be disabled","messagePattern":"plugin (.+?) cannot be disabled","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":849,"sourceCode":"                        parg = args[i]\n                    except IndexError:\n                        return\n                    i += 1\n                elif opt.startswith(\"-p\"):\n                    parg = opt[2:]\n                else:\n                    continue\n                parg = parg.strip()\n                if exclude_only and not parg.startswith(\"no:\"):\n                    continue\n                self.consider_pluginarg(parg)\n\n    def consider_pluginarg(self, arg: str) -> None:\n        \"\"\":meta private:\"\"\"\n        if arg.startswith(\"no:\"):\n            name = arg[3:]\n            if name in essential_plugins:\n                raise UsageError(f\"plugin {name} cannot be disabled\")\n\n            if name.endswith(\"conftest.py\"):\n                raise UsageError(\n                    f\"Blocking conftest files using -p is not supported: -p no:{name}\\n\"\n                    \"conftest.py files are not plugins and cannot be disabled via -p.\\n\"\n                )\n\n            # PR #4304: remove stepwise if cacheprovider is blocked.\n            if name == \"cacheprovider\":\n                self.set_blocked(\"stepwise\")\n                self.set_blocked(\"pytest_stepwise\")\n\n            self.set_blocked(name)\n            if not name.startswith(\"pytest_\"):\n                self.set_blocked(\"pytest_\" + name)\n        else:\n            name = arg\n            # Unblock the plugin.","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L831-L867","documentation":"Raised by consider_pluginarg() (src/_pytest/config/__init__.py:847) when a `-p no:<name>` argument names a plugin in essential_plugins (config/__init__.py:313-319: mark, main, runner, fixtures, helpconfig). These plugins are mandatory for pytest to function, so disabling them is rejected with UsageError before set_blocked() is called.","triggerScenarios":"Invoking `pytest -p no:mark`, `-p no:main`, `-p no:runner`, `-p no:fixtures`, or `-p no:helpconfig`. The check at config/__init__.py:850-851 matches the stripped name against the essential_plugins tuple.","commonSituations":"Trying to shave startup time by disabling builtins; misreading docs that suggest `-p no:X` works for every plugin; copy-pasting a `-p no:...` block from a CI config.","solutions":["Remove the `-p no:<essential>` argument from your CLI, PYTEST_ADDOPTS, or addopts","If you need to disable some behavior of these plugins, find the specific ini option (e.g. use -p no:cacheprovider instead of disabling something essential)","Replace the goal: for marker filtering use --markers/-m filters rather than disabling the mark plugin"],"exampleFix":"// before\npytest -p no:fixtures tests/\n// after\npytest tests/","handlingStrategy":"validation","validationCode":"from _pytest.config import essential_plugins\nname = arg[3:]  # strip 'no:'\nif name in essential_plugins:\n    raise ValueError(f'Cannot disable essential plugin: {name}')","typeGuard":"from _pytest.config import essential_plugins\ndef is_disableable(name: str) -> bool:\n    return name not in essential_plugins","tryCatchPattern":"from _pytest.config import UsageError\ntry:\n    pytest.main(['-p', f'no:{name}'])\nexcept UsageError as e:\n    print(e)","preventionTips":["Treat mark/main/runner/fixtures/helpconfig as untouchable","Filter user-supplied -p args through the essential_plugins tuple before passing to pytest","Document in CI config which plugins may be safely disabled"],"tags":["plugin","cli","config","validation"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}