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
- Use --noconftest to prevent conftest.py files from being loaded.
- Move or rename the conftest.py if it should not apply to the current run.
- 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
- Use --noconftest to suppress all conftest.py loading.
- Never pass a conftest.py path to -p no:; conftest files are handled by the collection system, not the plugin system.
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
- plugin {name} cannot be disabled
- Plugins may be specified as a sequence or a ','-separated st
- Missing required plugins: {}
- -o/--override-ini expects option=value style (got: {ini_conf
- Directory '{rootdir}' not found. Check your '--rootdir' opti
AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04).
Data as JSON: /data/errors/bc2502a6c31cd162.json.
Report an issue: GitHub.