Skip to content

Commit 553951c

Browse files
committed
Fix some issues related to "-p no:X" with default_plugins
1 parent 15ef168 commit 553951c

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ def _consider_importhook(self, args):
762762
by the importhook.
763763
"""
764764
ns, unknown_args = self._parser.parse_known_and_unknown_args(args)
765-
mode = ns.assertmode
765+
mode = getattr(ns, "assertmode", "plain")
766766
if mode == "rewrite":
767767
try:
768768
hook = _pytest.assertion.install_importhook(self)

src/_pytest/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def _collect(self, arg):
548548
# Start with a Session root, and delve to argpath item (dir or file)
549549
# and stack all Packages found on the way.
550550
# No point in finding packages when collecting doctests
551-
if not self.config.option.doctestmodules:
551+
if not self.config.getoption("doctestmodules", False):
552552
pm = self.config.pluginmanager
553553
for parent in reversed(argpath.parts()):
554554
if pm._confcutdir and pm._confcutdir.relto(parent):

src/_pytest/runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def runtestprotocol(item, log=True, nextitem=None):
8787
rep = call_and_report(item, "setup", log)
8888
reports = [rep]
8989
if rep.passed:
90-
if item.config.option.setupshow:
90+
if item.config.getoption("setupshow", False):
9191
show_test_item(item)
92-
if not item.config.option.setuponly:
92+
if not item.config.getoption("setuponly", False):
9393
reports.append(call_and_report(item, "call", log))
9494
reports.append(call_and_report(item, "teardown", log, nextitem=nextitem))
9595
# after all teardown hooks have been called
@@ -192,7 +192,7 @@ def call_runtest_hook(item, when, **kwds):
192192
hookname = "pytest_runtest_" + when
193193
ihook = getattr(item.ihook, hookname)
194194
reraise = (Exit,)
195-
if not item.config.getvalue("usepdb"):
195+
if not item.config.getoption("usepdb", False):
196196
reraise += (KeyboardInterrupt,)
197197
return CallInfo.from_call(
198198
lambda: ihook(item=item, **kwds), when=when, reraise=reraise

src/_pytest/terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _determine_show_progress_info(self):
251251
if self.config.getoption("capture", "no") == "no":
252252
return False
253253
# do not show progress if we are showing fixture setup/teardown
254-
if self.config.getoption("setupshow"):
254+
if self.config.getoption("setupshow", False):
255255
return False
256256
return self.config.getini("console_output_style") in ("progress", "count")
257257

testing/test_config.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from _pytest.config.findpaths import get_common_ancestor
1616
from _pytest.config.findpaths import getcfg
1717
from _pytest.main import EXIT_NOTESTSCOLLECTED
18+
from _pytest.main import EXIT_OK
1819
from _pytest.main import EXIT_TESTSFAILED
1920
from _pytest.main import EXIT_USAGEERROR
2021

@@ -1189,3 +1190,41 @@ def test_config_does_not_load_blocked_plugin_from_args(testdir):
11891190
result = testdir.runpytest(str(p), "-pno:capture", "-s")
11901191
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
11911192
assert result.ret == EXIT_USAGEERROR
1193+
1194+
1195+
@pytest.mark.parametrize(
1196+
"plugin",
1197+
[
1198+
x
1199+
for x in _pytest.config.default_plugins
1200+
if x
1201+
not in [
1202+
"fixtures",
1203+
"helpconfig", # Provides -p.
1204+
"main",
1205+
"mark",
1206+
"python",
1207+
"runner",
1208+
"terminal", # works in OK case (no output), but not with failures.
1209+
]
1210+
],
1211+
)
1212+
def test_config_blocked_default_plugins(testdir, plugin):
1213+
if plugin == "debugging":
1214+
# https://github.com/pytest-dev/pytest-xdist/pull/422
1215+
try:
1216+
import xdist # noqa: F401
1217+
except ImportError:
1218+
pass
1219+
else:
1220+
pytest.skip("does not work with xdist currently")
1221+
1222+
p = testdir.makepyfile("def test(): pass")
1223+
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
1224+
assert result.ret == EXIT_OK
1225+
result.stdout.fnmatch_lines(["* 1 passed in *"])
1226+
1227+
p = testdir.makepyfile("def test(): assert 0")
1228+
result = testdir.runpytest(str(p), "-pno:%s" % plugin)
1229+
assert result.ret == EXIT_TESTSFAILED
1230+
result.stdout.fnmatch_lines(["* 1 failed in *"])

0 commit comments

Comments
 (0)