{"record":{"id":"bc2502a6c31cd162","repo":"pytest-dev/pytest","slug":"blocking-conftest-files-using-p-is-not-supported","errorCode":null,"errorMessage":"Blocking conftest files using -p is not supported: -p no:{name}\nconftest.py files are not plugins and cannot be disabled via -p.\n","messagePattern":"Blocking conftest files using -p is not supported: -p no:(.+?)\nconftest\\.py files are not plugins and cannot be disabled via -p\\.\n","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":852,"sourceCode":"                    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.\n            self.unblock(name)\n            if not name.startswith(\"pytest_\"):\n                self.unblock(\"pytest_\" + name)","sourceCodeStart":834,"sourceCodeEnd":870,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L834-L870","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Use --noconftest to skip ALL conftest.py loading (heavy-handed but supported)","Use --confcutdir to bound how deep pytest searches for conftest.py files","Edit the conftest.py to guard its side effects behind a conditional"],"exampleFix":"// before\npytest -p no:tests/conftest.py\n// after\npytest --noconftest tests/","handlingStrategy":"validation","validationCode":"name = arg[3:]  # strip 'no:'\nif name.endswith('conftest.py'):\n    raise ValueError(f'conftest.py cannot be disabled via -p; use --noconftest')","typeGuard":"def is_plugin_not_conftest(name: str) -> bool:\n    return not name.endswith('conftest.py')","tryCatchPattern":"from _pytest.config import UsageError\ntry:\n    pytest.main(['-p', arg])\nexcept UsageError as e:\n    print(e)","preventionTips":["Use --noconftest to skip ALL conftest.py loading rather than -p no:<conftest>","Use --confcutdir to bound conftest.py discovery if you only want to limit scope","Edit conftest.py side-effects to be conditional instead of trying to disable the file"],"tags":["plugin","conftest","cli","config"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}