From 553951c44381bf554a20d656534f616873f0fbc6 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 21 Mar 2019 04:50:51 +0100 Subject: [PATCH] Fix some issues related to "-p no:X" with default_plugins --- src/_pytest/config/__init__.py | 2 +- src/_pytest/main.py | 2 +- src/_pytest/runner.py | 6 +++--- src/_pytest/terminal.py | 2 +- testing/test_config.py | 39 ++++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b2e4fd774..2ab1d0790 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -762,7 +762,7 @@ class Config(object): by the importhook. """ ns, unknown_args = self._parser.parse_known_and_unknown_args(args) - mode = ns.assertmode + mode = getattr(ns, "assertmode", "plain") if mode == "rewrite": try: hook = _pytest.assertion.install_importhook(self) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d8478d4fc..3effbfb6e 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -548,7 +548,7 @@ class Session(nodes.FSCollector): # Start with a Session root, and delve to argpath item (dir or file) # and stack all Packages found on the way. # 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 for parent in reversed(argpath.parts()): if pm._confcutdir and pm._confcutdir.relto(parent): diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 6ca438849..1f09f42e8 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -87,9 +87,9 @@ def runtestprotocol(item, log=True, nextitem=None): rep = call_and_report(item, "setup", log) reports = [rep] if rep.passed: - if item.config.option.setupshow: + if item.config.getoption("setupshow", False): 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, "teardown", log, nextitem=nextitem)) # after all teardown hooks have been called @@ -192,7 +192,7 @@ def call_runtest_hook(item, when, **kwds): hookname = "pytest_runtest_" + when ihook = getattr(item.ihook, hookname) reraise = (Exit,) - if not item.config.getvalue("usepdb"): + if not item.config.getoption("usepdb", False): reraise += (KeyboardInterrupt,) return CallInfo.from_call( lambda: ihook(item=item, **kwds), when=when, reraise=reraise diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 3537ae445..06604fdf1 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -251,7 +251,7 @@ class TerminalReporter(object): if self.config.getoption("capture", "no") == "no": return False # 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 self.config.getini("console_output_style") in ("progress", "count") diff --git a/testing/test_config.py b/testing/test_config.py index 50a40a2cb..57cbd10ee 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -15,6 +15,7 @@ from _pytest.config.findpaths import determine_setup from _pytest.config.findpaths import get_common_ancestor from _pytest.config.findpaths import getcfg from _pytest.main import EXIT_NOTESTSCOLLECTED +from _pytest.main import EXIT_OK from _pytest.main import EXIT_TESTSFAILED 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.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"]) 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 *"])