fix #2527 - introduce a option to pic the empty parameterset action
This commit is contained in:
parent
bf2c10c810
commit
37b41de779
|
@ -95,11 +95,17 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
|
||||||
|
|
||||||
|
|
||||||
def get_empty_parameterset_mark(config, argnames, function):
|
def get_empty_parameterset_mark(config, argnames, function):
|
||||||
|
requested_mark = config.getini('empty_parameterset')
|
||||||
|
if requested_mark in ('', None, 'skip'):
|
||||||
|
mark = MARK_GEN.skip
|
||||||
|
elif requested_mark == 'xfail':
|
||||||
|
mark = MARK_GEN.xfail(run=False)
|
||||||
|
else:
|
||||||
|
raise LookupError(requested_mark)
|
||||||
fs, lineno = getfslineno(function)
|
fs, lineno = getfslineno(function)
|
||||||
reason = "got empty parameter set %r, function %s at %s:%d" % (
|
reason = "got empty parameter set %r, function %s at %s:%d" % (
|
||||||
argnames, function.__name__, fs, lineno)
|
argnames, function.__name__, fs, lineno)
|
||||||
return MARK_GEN.skip(reason=reason)
|
return mark(reason=reason)
|
||||||
|
|
||||||
|
|
||||||
class MarkerError(Exception):
|
class MarkerError(Exception):
|
||||||
|
@ -141,6 +147,9 @@ def pytest_addoption(parser):
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.addini("markers", "markers for test functions", 'linelist')
|
parser.addini("markers", "markers for test functions", 'linelist')
|
||||||
|
parser.addini(
|
||||||
|
"empty_parameterset",
|
||||||
|
"default marker for empty parametersets")
|
||||||
|
|
||||||
|
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
|
@ -284,6 +293,14 @@ def pytest_configure(config):
|
||||||
if config.option.strict:
|
if config.option.strict:
|
||||||
MARK_GEN._config = config
|
MARK_GEN._config = config
|
||||||
|
|
||||||
|
empty_parameterset = config.getini("empty_parameterset")
|
||||||
|
|
||||||
|
if empty_parameterset not in ('skip', 'xfail', None, ''):
|
||||||
|
from pytest import UsageError
|
||||||
|
raise UsageError(
|
||||||
|
"empty_parameterset must be one of skip and xfail,"
|
||||||
|
" but it is {!r}".format(empty_parameterset))
|
||||||
|
|
||||||
|
|
||||||
def pytest_unconfigure(config):
|
def pytest_unconfigure(config):
|
||||||
MARK_GEN._config = getattr(config, '_old_mark_config', None)
|
MARK_GEN._config = getattr(config, '_old_mark_config', None)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
introduce a pytest ini option to pick the mark for empty parametersets and allow to use xfail(run=False)
|
|
@ -891,3 +891,26 @@ class TestMarkDecorator(object):
|
||||||
])
|
])
|
||||||
def test__eq__(self, lhs, rhs, expected):
|
def test__eq__(self, lhs, rhs, expected):
|
||||||
assert (lhs == rhs) == expected
|
assert (lhs == rhs) == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('mark', [None, 'skip', 'xfail'])
|
||||||
|
def test_parameterset_for_parametrize_marks(testdir, mark):
|
||||||
|
if mark is not None:
|
||||||
|
testdir.makeini("[pytest]\nempty_parameterset=" + mark)
|
||||||
|
|
||||||
|
config = testdir.parseconfig()
|
||||||
|
from _pytest.mark import pytest_configure, get_empty_parameterset_mark
|
||||||
|
pytest_configure(config)
|
||||||
|
result_mark = get_empty_parameterset_mark(config, ['a'], all)
|
||||||
|
if mark is None:
|
||||||
|
# normalize to the requested name
|
||||||
|
mark = 'skip'
|
||||||
|
assert result_mark.name == mark
|
||||||
|
|
||||||
|
if mark == 'xfail':
|
||||||
|
assert result_mark.kwargs.get('run') is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_parameterset_for_parametrize_bad_markname(testdir):
|
||||||
|
with pytest.raises(pytest.UsageError):
|
||||||
|
test_parameterset_for_parametrize_marks(testdir, 'bad')
|
||||||
|
|
Loading…
Reference in New Issue