diff --git a/_pytest/mark.py b/_pytest/mark.py index 03b058d95..a5c972e5d 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -7,6 +7,7 @@ from collections import namedtuple from operator import attrgetter from six.moves import map from .deprecated import MARK_PARAMETERSET_UNPACKING +from .compat import NOTSET, getfslineno def alias(name, warning=None): @@ -67,6 +68,30 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')): return cls(argval, marks=newmarks, id=None) + @classmethod + def _for_parameterize(cls, argnames, argvalues, function): + if not isinstance(argnames, (tuple, list)): + argnames = [x.strip() for x in argnames.split(",") if x.strip()] + force_tuple = len(argnames) == 1 + else: + force_tuple = False + parameters = [ + ParameterSet.extract_from(x, legacy_force_tuple=force_tuple) + for x in argvalues] + del argvalues + + if not parameters: + fs, lineno = getfslineno(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( + values=(NOTSET,) * len(argnames), + marks=[mark], + id=None, + )) + return argnames, parameters + class MarkerError(Exception): diff --git a/_pytest/python.py b/_pytest/python.py index c47422937..83e8dad9a 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -769,30 +769,12 @@ class Metafunc(fixtures.FuncargnamesCompatAttr): to set a dynamic scope using test context or configuration. """ from _pytest.fixtures import scope2index - from _pytest.mark import MARK_GEN, ParameterSet + from _pytest.mark import ParameterSet from py.io import saferepr - - if not isinstance(argnames, (tuple, list)): - argnames = [x.strip() for x in argnames.split(",") if x.strip()] - force_tuple = len(argnames) == 1 - else: - force_tuple = False - parameters = [ - ParameterSet.extract_from(x, legacy_force_tuple=force_tuple) - for x in argvalues] + argnames, parameters = ParameterSet._for_parameterize( + argnames, argvalues, self.function) del argvalues - if not parameters: - fs, lineno = getfslineno(self.function) - reason = "got empty parameter set %r, function %s at %s:%d" % ( - argnames, self.function.__name__, fs, lineno) - mark = MARK_GEN.skip(reason=reason) - parameters.append(ParameterSet( - values=(NOTSET,) * len(argnames), - marks=[mark], - id=None, - )) - if scope is None: scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect) diff --git a/changelog/2877.trivial b/changelog/2877.trivial new file mode 100644 index 000000000..aaf58b039 --- /dev/null +++ b/changelog/2877.trivial @@ -0,0 +1 @@ +internal move of the parameterset extraction to a more maintainable place \ No newline at end of file