Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ Michael Goerz
Michael Krebs
Michael Seifert
Michael Vogt
Michael Reznik
Michal Wajszczuk
Michał Górny
Michał Zięba
Expand Down
5 changes: 5 additions & 0 deletions changelog/13634.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Blocking a ``conftest.py`` file using the ``-p no:`` option is now explicitly disallowed.

Previously this resulted in an internal assertion failure during plugin loading.

Pytest now raises a clear ``UsageError`` explaining that conftest files are not plugins and cannot be disabled via ``-p``.
6 changes: 6 additions & 0 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,12 @@ def consider_pluginarg(self, arg: str) -> None:
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")
Expand Down
4 changes: 4 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,10 @@ def test_config_does_not_load_blocked_plugin_from_args(pytester: Pytester) -> No
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
assert result.ret == ExitCode.USAGE_ERROR

result = pytester.runpytest(str(p), "-p no:/path/to/conftest.py", "-s")
result.stderr.fnmatch_lines(["ERROR:*Blocking conftest files*"])
assert result.ret == ExitCode.USAGE_ERROR


def test_invocation_args(pytester: Pytester) -> None:
"""Ensure that Config.invocation_* arguments are correctly defined"""
Expand Down