Skip to content

Commit 32a8d50

Browse files
authored
Merge pull request #5005 from blueyed/essential_plugins
Split out list of essential plugins
2 parents 1c9dcf1 + 8c734df commit 32a8d50

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

src/_pytest/config/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,18 @@ def directory_arg(path, optname):
112112
return path
113113

114114

115-
default_plugins = (
115+
# Plugins that cannot be disabled via "-p no:X" currently.
116+
essential_plugins = (
116117
"mark",
117118
"main",
118-
"terminal",
119119
"runner",
120120
"python",
121121
"fixtures",
122+
"helpconfig", # Provides -p.
123+
)
124+
125+
default_plugins = essential_plugins + (
126+
"terminal", # Has essential options, but xdist uses -pno:terminal.
122127
"debugging",
123128
"unittest",
124129
"capture",
@@ -127,7 +132,6 @@ def directory_arg(path, optname):
127132
"monkeypatch",
128133
"recwarn",
129134
"pastebin",
130-
"helpconfig",
131135
"nose",
132136
"assertion",
133137
"junitxml",
@@ -143,7 +147,6 @@ def directory_arg(path, optname):
143147
"reports",
144148
)
145149

146-
147150
builtin_plugins = set(default_plugins)
148151
builtin_plugins.add("pytester")
149152

@@ -496,6 +499,9 @@ def consider_preparse(self, args):
496499
def consider_pluginarg(self, arg):
497500
if arg.startswith("no:"):
498501
name = arg[3:]
502+
if name in essential_plugins:
503+
raise UsageError("plugin %s cannot be disabled" % name)
504+
499505
# PR #4304 : remove stepwise if cacheprovider is blocked
500506
if name == "cacheprovider":
501507
self.set_blocked("stepwise")

src/_pytest/terminal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def getreportopt(config):
173173
return reportopts
174174

175175

176+
@pytest.hookimpl(trylast=True) # after _pytest.runner
176177
def pytest_report_teststatus(report):
177178
if report.passed:
178179
letter = "."

testing/test_config.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,20 +1205,12 @@ def test_config_does_not_load_blocked_plugin_from_args(testdir):
12051205
[
12061206
x
12071207
for x in _pytest.config.default_plugins
1208-
if x
1209-
not in [
1210-
"fixtures",
1211-
"helpconfig", # Provides -p.
1212-
"main",
1213-
"mark",
1214-
"python",
1215-
"runner",
1216-
"terminal", # works in OK case (no output), but not with failures.
1217-
]
1208+
if x not in _pytest.config.essential_plugins
12181209
],
12191210
)
12201211
def test_config_blocked_default_plugins(testdir, plugin):
12211212
if plugin == "debugging":
1213+
# Fixed in xdist master (after 1.27.0).
12221214
# https://github.com/pytest-dev/pytest-xdist/pull/422
12231215
try:
12241216
import xdist # noqa: F401
@@ -1230,9 +1222,11 @@ def test_config_blocked_default_plugins(testdir, plugin):
12301222
p = testdir.makepyfile("def test(): pass")
12311223
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
12321224
assert result.ret == EXIT_OK
1233-
result.stdout.fnmatch_lines(["* 1 passed in *"])
1234-
1235-
p = testdir.makepyfile("def test(): assert 0")
1236-
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
1237-
assert result.ret == EXIT_TESTSFAILED
1238-
result.stdout.fnmatch_lines(["* 1 failed in *"])
1225+
if plugin != "terminal":
1226+
result.stdout.fnmatch_lines(["* 1 passed in *"])
1227+
1228+
if plugin != "terminal": # fails to report due to its options being used elsewhere.
1229+
p = testdir.makepyfile("def test(): assert 0")
1230+
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
1231+
assert result.ret == EXIT_TESTSFAILED
1232+
result.stdout.fnmatch_lines(["* 1 failed in *"])

testing/test_pluginmanager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pytest
1111
from _pytest.config import PytestPluginManager
12+
from _pytest.config.exceptions import UsageError
1213
from _pytest.main import EXIT_NOTESTSCOLLECTED
1314
from _pytest.main import Session
1415

@@ -314,6 +315,9 @@ def test_preparse_args(self, pytestpm):
314315
# Handles -p without following arg (when used without argparse).
315316
pytestpm.consider_preparse(["-p"])
316317

318+
with pytest.raises(UsageError, match="^plugin main cannot be disabled$"):
319+
pytestpm.consider_preparse(["-p", "no:main"])
320+
317321
def test_plugin_prevent_register(self, pytestpm):
318322
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
319323
l1 = pytestpm.get_plugins()

0 commit comments

Comments
 (0)