Skip to content

Commit 004a967

Browse files
Show better error when blocking conftest files via -p (#14018)
Show a clear message when `-p` is used for a `conftest.py` file, instead of raising an internal assertion error. Fixes #13634
1 parent 8f5b07d commit 004a967

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
@@ -312,6 +312,7 @@ Michael Goerz
312312
Michael Krebs
313313
Michael Seifert
314314
Michael Vogt
315+
Michael Reznik
315316
Michal Wajszczuk
316317
Michał Górny
317318
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
@@ -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
@@ -2475,6 +2475,10 @@ def test_config_does_not_load_blocked_plugin_from_args(pytester: Pytester) -> No
24752475
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
24762476
assert result.ret == ExitCode.USAGE_ERROR
24772477

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

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

0 commit comments

Comments
 (0)