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:
		
						commit
						0e6cf0ff28
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 *"])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue