parameterset: refactor marking empty parametersets

This commit is contained in:
Ronny Pfannschmidt 2017-12-17 11:26:51 +01:00
parent b8be339632
commit bf2c10c810
2 changed files with 11 additions and 6 deletions

View File

@ -73,7 +73,7 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
return cls(argval, marks=newmarks, id=None) return cls(argval, marks=newmarks, id=None)
@classmethod @classmethod
def _for_parameterize(cls, argnames, argvalues, function): def _for_parameterize(cls, argnames, argvalues, function, config):
if not isinstance(argnames, (tuple, list)): if not isinstance(argnames, (tuple, list)):
argnames = [x.strip() for x in argnames.split(",") if x.strip()] argnames = [x.strip() for x in argnames.split(",") if x.strip()]
force_tuple = len(argnames) == 1 force_tuple = len(argnames) == 1
@ -85,10 +85,7 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
del argvalues del argvalues
if not parameters: if not parameters:
fs, lineno = getfslineno(function) mark = get_empty_parameterset_mark(config, argnames, function)
reason = "got empty parameter set %r, function %s at %s:%d" % (
argnames, function.__name__, fs, lineno)
mark = MARK_GEN.skip(reason=reason)
parameters.append(ParameterSet( parameters.append(ParameterSet(
values=(NOTSET,) * len(argnames), values=(NOTSET,) * len(argnames),
marks=[mark], marks=[mark],
@ -97,6 +94,14 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
return argnames, parameters return argnames, parameters
def get_empty_parameterset_mark(config, argnames, function):
fs, lineno = getfslineno(function)
reason = "got empty parameter set %r, function %s at %s:%d" % (
argnames, function.__name__, fs, lineno)
return MARK_GEN.skip(reason=reason)
class MarkerError(Exception): class MarkerError(Exception):
"""Error in use of a pytest marker/attribute.""" """Error in use of a pytest marker/attribute."""

View File

@ -786,7 +786,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
from _pytest.mark import ParameterSet from _pytest.mark import ParameterSet
from py.io import saferepr from py.io import saferepr
argnames, parameters = ParameterSet._for_parameterize( argnames, parameters = ParameterSet._for_parameterize(
argnames, argvalues, self.function) argnames, argvalues, self.function, self.config)
del argvalues del argvalues
if scope is None: if scope is None: