diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 3c161c4a6..e3a07f021 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -111,7 +111,19 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")): ] del argvalues - if not parameters: + if parameters: + # check all parameter sets have the correct number of values + for param in parameters: + if len(param.values) != len(argnames): + raise ValueError( + 'In "parametrize" the number of values ({}) must be ' + "equal to the number of names ({})".format( + param.values, argnames + ) + ) + else: + # empty parameter set (likely computed at runtime): create a single + # parameter set with NOSET values, with the "empty parameter set" mark applied to it mark = get_empty_parameterset_mark(config, argnames, func) parameters.append( ParameterSet(values=(NOTSET,) * len(argnames), marks=[mark], id=None) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 4d0b4d537..02e9381a5 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -8,7 +8,6 @@ import os import collections import warnings from textwrap import dedent -from itertools import count import py @@ -887,22 +886,14 @@ class Metafunc(fixtures.FuncargnamesCompatAttr): # of all calls newcalls = [] for callspec in self._calls or [CallSpec2(self)]: - elements = zip(ids, parameters, count()) - for a_id, param, param_index in elements: - if len(param.values) != len(argnames): - raise ValueError( - 'In "parametrize" the number of values ({}) must be ' - "equal to the number of names ({})".format( - param.values, argnames - ) - ) + for param_index, (param_id, param_set) in enumerate(zip(ids, parameters)): newcallspec = callspec.copy() newcallspec.setmulti2( arg_values_types, argnames, - param.values, - a_id, - param.marks, + param_set.values, + param_id, + param_set.marks, scopenum, param_index, )