Skip to content

Commit e2d53d1

Browse files
Show better error when blocking conftest files via -p (#14018) (#14074)
Show a clear message when `-p` is used for a `conftest.py` file, instead of raising an internal assertion error. Fixes #13634 (cherry picked from commit 004a967) Co-authored-by: Bubble-Interface <[email protected]>
1 parent 35dfe8d commit e2d53d1

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ Michael Goerz
311311
Michael Krebs
312312
Michael Seifert
313313
Michael Vogt
314+
Michael Reznik
314315
Michal Wajszczuk
315316
Michał Górny
316317
Michał Zięba

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
@@ -814,6 +814,12 @@ def consider_pluginarg(self, arg: str) -> None:
814814
if name in essential_plugins:
815815
raise UsageError(f"plugin {name} cannot be disabled")
816816

817+
if name.endswith("conftest.py"):
818+
raise UsageError(
819+
f"Blocking conftest files using -p is not supported: -p no:{name}\n"
820+
"conftest.py files are not plugins and cannot be disabled via -p.\n"
821+
)
822+
817823
# PR #4304: remove stepwise if cacheprovider is blocked.
818824
if name == "cacheprovider":
819825
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)