config: handle `-p no:plugin` with default plugins
`-p no:capture` should not load its fixtures in the first place.
This commit is contained in:
parent
da81c1e49a
commit
415899d428
|
@ -0,0 +1,3 @@
|
||||||
|
``-p no:plugin`` is handled correctly for default (internal) plugins now, e.g. with ``-p no:capture``.
|
||||||
|
|
||||||
|
Previously they were loaded (imported) always, making e.g. the ``capfd`` fixture available.
|
|
@ -147,10 +147,15 @@ builtin_plugins = set(default_plugins)
|
||||||
builtin_plugins.add("pytester")
|
builtin_plugins.add("pytester")
|
||||||
|
|
||||||
|
|
||||||
def get_config():
|
def get_config(args=None):
|
||||||
# subsequent calls to main will create a fresh instance
|
# subsequent calls to main will create a fresh instance
|
||||||
pluginmanager = PytestPluginManager()
|
pluginmanager = PytestPluginManager()
|
||||||
config = Config(pluginmanager)
|
config = Config(pluginmanager)
|
||||||
|
|
||||||
|
if args is not None:
|
||||||
|
# Handle any "-p no:plugin" args.
|
||||||
|
pluginmanager.consider_preparse(args)
|
||||||
|
|
||||||
for spec in default_plugins:
|
for spec in default_plugins:
|
||||||
pluginmanager.import_plugin(spec)
|
pluginmanager.import_plugin(spec)
|
||||||
return config
|
return config
|
||||||
|
@ -178,7 +183,7 @@ def _prepareconfig(args=None, plugins=None):
|
||||||
msg = "`args` parameter expected to be a list or tuple of strings, got: {!r} (type: {})"
|
msg = "`args` parameter expected to be a list or tuple of strings, got: {!r} (type: {})"
|
||||||
raise TypeError(msg.format(args, type(args)))
|
raise TypeError(msg.format(args, type(args)))
|
||||||
|
|
||||||
config = get_config()
|
config = get_config(args)
|
||||||
pluginmanager = config.pluginmanager
|
pluginmanager = config.pluginmanager
|
||||||
try:
|
try:
|
||||||
if plugins:
|
if plugins:
|
||||||
|
@ -713,7 +718,7 @@ class Config(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromdictargs(cls, option_dict, args):
|
def fromdictargs(cls, option_dict, args):
|
||||||
""" constructor useable for subprocesses. """
|
""" constructor useable for subprocesses. """
|
||||||
config = get_config()
|
config = get_config(args)
|
||||||
config.option.__dict__.update(option_dict)
|
config.option.__dict__.update(option_dict)
|
||||||
config.parse(args, addopts=False)
|
config.parse(args, addopts=False)
|
||||||
for x in config.option.plugins:
|
for x in config.option.plugins:
|
||||||
|
|
|
@ -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_TESTSFAILED
|
||||||
from _pytest.main import EXIT_USAGEERROR
|
from _pytest.main import EXIT_USAGEERROR
|
||||||
|
|
||||||
|
|
||||||
|
@ -1176,3 +1177,15 @@ def test_help_and_version_after_argument_error(testdir):
|
||||||
["*pytest*{}*imported from*".format(pytest.__version__)]
|
["*pytest*{}*imported from*".format(pytest.__version__)]
|
||||||
)
|
)
|
||||||
assert result.ret == EXIT_USAGEERROR
|
assert result.ret == EXIT_USAGEERROR
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_does_not_load_blocked_plugin_from_args(testdir):
|
||||||
|
"""This tests that pytest's config setup handles "-p no:X"."""
|
||||||
|
p = testdir.makepyfile("def test(capfd): pass")
|
||||||
|
result = testdir.runpytest(str(p), "-pno:capture", "--tb=native")
|
||||||
|
result.stdout.fnmatch_lines(["E fixture 'capfd' not found"])
|
||||||
|
assert result.ret == EXIT_TESTSFAILED
|
||||||
|
|
||||||
|
result = testdir.runpytest(str(p), "-pno:capture", "-s")
|
||||||
|
result.stderr.fnmatch_lines(["*: error: unrecognized arguments: -s"])
|
||||||
|
assert result.ret == EXIT_USAGEERROR
|
||||||
|
|
Loading…
Reference in New Issue