Merge pull request #4967 from blueyed/p-no-default

Fix some issues related to "-p no:X" with default_plugins
This commit is contained in:
Daniel Hahler 2019-03-21 17:02:34 +01:00 committed by GitHub
commit 0e6cf0ff28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 6 deletions

View File

@ -762,7 +762,7 @@ class Config(object):
by the importhook. by the importhook.
""" """
ns, unknown_args = self._parser.parse_known_and_unknown_args(args) ns, unknown_args = self._parser.parse_known_and_unknown_args(args)
mode = ns.assertmode mode = getattr(ns, "assertmode", "plain")
if mode == "rewrite": if mode == "rewrite":
try: try:
hook = _pytest.assertion.install_importhook(self) hook = _pytest.assertion.install_importhook(self)

View File

@ -548,7 +548,7 @@ class Session(nodes.FSCollector):
# Start with a Session root, and delve to argpath item (dir or file) # Start with a Session root, and delve to argpath item (dir or file)
# and stack all Packages found on the way. # and stack all Packages found on the way.
# No point in finding packages when collecting doctests # No point in finding packages when collecting doctests
if not self.config.option.doctestmodules: if not self.config.getoption("doctestmodules", False):
pm = self.config.pluginmanager pm = self.config.pluginmanager
for parent in reversed(argpath.parts()): for parent in reversed(argpath.parts()):
if pm._confcutdir and pm._confcutdir.relto(parent): if pm._confcutdir and pm._confcutdir.relto(parent):

View File

@ -87,9 +87,9 @@ def runtestprotocol(item, log=True, nextitem=None):
rep = call_and_report(item, "setup", log) rep = call_and_report(item, "setup", log)
reports = [rep] reports = [rep]
if rep.passed: if rep.passed:
if item.config.option.setupshow: if item.config.getoption("setupshow", False):
show_test_item(item) show_test_item(item)
if not item.config.option.setuponly: if not item.config.getoption("setuponly", False):
reports.append(call_and_report(item, "call", log)) reports.append(call_and_report(item, "call", log))
reports.append(call_and_report(item, "teardown", log, nextitem=nextitem)) reports.append(call_and_report(item, "teardown", log, nextitem=nextitem))
# after all teardown hooks have been called # after all teardown hooks have been called
@ -192,7 +192,7 @@ def call_runtest_hook(item, when, **kwds):
hookname = "pytest_runtest_" + when hookname = "pytest_runtest_" + when
ihook = getattr(item.ihook, hookname) ihook = getattr(item.ihook, hookname)
reraise = (Exit,) reraise = (Exit,)
if not item.config.getvalue("usepdb"): if not item.config.getoption("usepdb", False):
reraise += (KeyboardInterrupt,) reraise += (KeyboardInterrupt,)
return CallInfo.from_call( return CallInfo.from_call(
lambda: ihook(item=item, **kwds), when=when, reraise=reraise lambda: ihook(item=item, **kwds), when=when, reraise=reraise

View File

@ -251,7 +251,7 @@ class TerminalReporter(object):
if self.config.getoption("capture", "no") == "no": if self.config.getoption("capture", "no") == "no":
return False return False
# do not show progress if we are showing fixture setup/teardown # do not show progress if we are showing fixture setup/teardown
if self.config.getoption("setupshow"): if self.config.getoption("setupshow", False):
return False return False
return self.config.getini("console_output_style") in ("progress", "count") return self.config.getini("console_output_style") in ("progress", "count")

View File

@ -15,6 +15,7 @@ from _pytest.config.findpaths import determine_setup
from _pytest.config.findpaths import get_common_ancestor from _pytest.config.findpaths import get_common_ancestor
from _pytest.config.findpaths import getcfg from _pytest.config.findpaths import getcfg
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import EXIT_OK
from _pytest.main import EXIT_TESTSFAILED from _pytest.main import EXIT_TESTSFAILED
from _pytest.main import EXIT_USAGEERROR from _pytest.main import EXIT_USAGEERROR
@ -1189,3 +1190,41 @@ def test_config_does_not_load_blocked_plugin_from_args(testdir):
result = testdir.runpytest(str(p), "-pno:capture", "-s") result = testdir.runpytest(str(p), "-pno:capture", "-s")
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"]) result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
assert result.ret == EXIT_USAGEERROR assert result.ret == EXIT_USAGEERROR
@pytest.mark.parametrize(
"plugin",
[
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.
]
],
)
def test_config_blocked_default_plugins(testdir, plugin):
if plugin == "debugging":
# https://github.com/pytest-dev/pytest-xdist/pull/422
try:
import xdist # noqa: F401
except ImportError:
pass
else:
pytest.skip("does not work with xdist currently")
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 *"])