Skip to content

Commit 53e4c47

Browse files
config: catch conftest blocking
1 parent 922b603 commit 53e4c47

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

changelog/13634.bugfix.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Blocking a ``conftest.py`` file using the ``-p no:`` option is now explicitly disallowed.
2+
3+
Previously this resulted in an internal assertion failure during plugin loading.
4+
5+
Pytest now raises a clear ``UsageError`` explaining that conftest files are not plugins and cannot be disabled via ``-p``.

src/_pytest/config/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ def consider_pluginarg(self, arg: str) -> None:
816816
if name in essential_plugins:
817817
raise UsageError(f"plugin {name} cannot be disabled")
818818

819+
if name.endswith("conftest.py"):
820+
raise UsageError(
821+
f"Blocking conftest files using -p is not supported: -p no:{name}\n"
822+
"conftest.py files are not plugins and cannot be disabled via -p.\n"
823+
)
824+
819825
# PR #4304: remove stepwise if cacheprovider is blocked.
820826
if name == "cacheprovider":
821827
self.set_blocked("stepwise")

testing/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,10 @@ def test_config_does_not_load_blocked_plugin_from_args(pytester: Pytester) -> No
24602460
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
24612461
assert result.ret == ExitCode.USAGE_ERROR
24622462

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

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

0 commit comments

Comments
 (0)