From 4a436f225532e019787f5ef88be949e826928e21 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 27 Oct 2017 17:52:14 +0200 Subject: [PATCH 1/2] move responsibility for parameterset extraction into parameterset class --- _pytest/mark.py | 25 +++++++++++++++++++++++++ _pytest/python.py | 24 +++--------------------- changelog/2877.trivial | 1 + 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 changelog/2877.trivial diff --git a/_pytest/mark.py b/_pytest/mark.py index 03b058d95b9..a5c972e5d21 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -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): @@ -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): diff --git a/_pytest/python.py b/_pytest/python.py index c47422937d3..83e8dad9a6f 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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) diff --git a/changelog/2877.trivial b/changelog/2877.trivial new file mode 100644 index 00000000000..aaf58b03935 --- /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 From 460cae02b0d48594730870ae0e6cf8cd9653b865 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 3 Nov 2017 16:51:59 -0200 Subject: [PATCH 2/2] Small formatting fix in CHANGELOG --- changelog/2877.trivial | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/2877.trivial b/changelog/2877.trivial index aaf58b03935..c4198af97f2 100644 --- a/changelog/2877.trivial +++ b/changelog/2877.trivial @@ -1 +1 @@ -internal move of the parameterset extraction to a more maintainable place \ No newline at end of file +Internal move of the parameterset extraction to a more maintainable place.