Skip to content

Commit

Permalink
Merge 4a436f2 into def471b
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Oct 27, 2017
2 parents def471b + 4a436f2 commit f98922b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
25 changes: 25 additions & 0 deletions _pytest/mark.py
Expand Up @@ -7,6 +7,7 @@
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):
Expand Down Expand Up @@ -67,6 +68,30 @@ def extract_from(cls, parameterset, legacy_force_tuple=False):

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):

Expand Down
24 changes: 3 additions & 21 deletions _pytest/python.py
Expand Up @@ -769,30 +769,12 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
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)

Expand Down
1 change: 1 addition & 0 deletions changelog/2877.trivial
@@ -0,0 +1 @@
internal move of the parameterset extraction to a more maintainable place

0 comments on commit f98922b

Please sign in to comment.