Skip to content
Merged
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
14 changes: 10 additions & 4 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,18 @@ def directory_arg(path, optname):
return path


default_plugins = (
# Plugins that cannot be disabled via "-p no:X" currently.
essential_plugins = (
"mark",
"main",
"terminal",
"runner",
"python",
"fixtures",
"helpconfig", # Provides -p.
)

default_plugins = essential_plugins + (
"terminal", # Has essential options, but xdist uses -pno:terminal.
"debugging",
"unittest",
"capture",
Expand All @@ -127,7 +132,6 @@ def directory_arg(path, optname):
"monkeypatch",
"recwarn",
"pastebin",
"helpconfig",
"nose",
"assertion",
"junitxml",
Expand All @@ -143,7 +147,6 @@ def directory_arg(path, optname):
"reports",
)


builtin_plugins = set(default_plugins)
builtin_plugins.add("pytester")

Expand Down Expand Up @@ -496,6 +499,9 @@ def consider_preparse(self, args):
def consider_pluginarg(self, arg):
if arg.startswith("no:"):
name = arg[3:]
if name in essential_plugins:
raise UsageError("plugin %s cannot be disabled" % name)

# PR #4304 : remove stepwise if cacheprovider is blocked
if name == "cacheprovider":
self.set_blocked("stepwise")
Expand Down
1 change: 1 addition & 0 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def getreportopt(config):
return reportopts


@pytest.hookimpl(trylast=True) # after _pytest.runner
def pytest_report_teststatus(report):
if report.passed:
letter = "."
Expand Down
26 changes: 10 additions & 16 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,20 +1205,12 @@ def test_config_does_not_load_blocked_plugin_from_args(testdir):
[
x
for x in _pytest.config.default_plugins
if x
not in [
"fixtures",
"helpconfig", # Provides -p.
"main",
"mark",
"python",
"runner",
"terminal", # works in OK case (no output), but not with failures.
]
if x not in _pytest.config.essential_plugins
],
)
def test_config_blocked_default_plugins(testdir, plugin):
if plugin == "debugging":
# Fixed in xdist master (after 1.27.0).
# https://github.com/pytest-dev/pytest-xdist/pull/422
try:
import xdist # noqa: F401
Expand All @@ -1230,9 +1222,11 @@ def test_config_blocked_default_plugins(testdir, plugin):
p = testdir.makepyfile("def test(): pass")
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
assert result.ret == EXIT_OK
result.stdout.fnmatch_lines(["* 1 passed in *"])

p = testdir.makepyfile("def test(): assert 0")
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
assert result.ret == EXIT_TESTSFAILED
result.stdout.fnmatch_lines(["* 1 failed in *"])
if plugin != "terminal":
result.stdout.fnmatch_lines(["* 1 passed in *"])

if plugin != "terminal": # fails to report due to its options being used elsewhere.
p = testdir.makepyfile("def test(): assert 0")
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
assert result.ret == EXIT_TESTSFAILED
result.stdout.fnmatch_lines(["* 1 failed in *"])
4 changes: 4 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest
from _pytest.config import PytestPluginManager
from _pytest.config.exceptions import UsageError
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import Session

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

with pytest.raises(UsageError, match="^plugin main cannot be disabled$"):
pytestpm.consider_preparse(["-p", "no:main"])

def test_plugin_prevent_register(self, pytestpm):
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
l1 = pytestpm.get_plugins()
Expand Down