Skip to content

Commit baa3f86

Browse files
author
Sylvain MARIE
committed
Fixed mistake in handling #148: resolution should always be light
1 parent 7279647 commit baa3f86

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pytest_cases/common_pytest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def make_test_ids(global_ids, id_marks, argnames=None, argvalues=None, precomput
224224
if global_ids is not None:
225225
# overridden at global pytest.mark.parametrize level - this takes precedence.
226226
# resolve possibly infinite generators of ids here
227-
p_ids = resolve_ids(global_ids, argvalues)
227+
p_ids = resolve_ids(global_ids, argvalues, full_resolve=True)
228228
else:
229229
# default: values-based
230230
if precomputed_ids is not None:
@@ -241,14 +241,23 @@ def make_test_ids(global_ids, id_marks, argnames=None, argvalues=None, precomput
241241
return p_ids
242242

243243

244-
def resolve_ids(ids, argvalues):
245-
"""Returns the list of ids to use by a parametrized fixture, based on the `ids` parameter and the `argvalues`"""
244+
def resolve_ids(ids, argvalues, full_resolve=False):
245+
"""
246+
Resolves the `ids` argument of a parametrized fixture.
247+
248+
If `full_resolve` is False (default), iterable ids will be resolved, but not callable ids. This is useful if the
249+
`argvalues` have not yet been cleaned of possible `pytest.param` wrappers.
246250
251+
If `full_resolve` is True, callable ids will be called using the argvalues, so the result is guaranteed to be a
252+
list.
253+
"""
247254
try: # an explicit list or generator of ids ?
248-
p_ids = list(id for id, v in zip(ids, argvalues))
255+
return list(id for id, v in zip(ids, argvalues))
249256
except TypeError: # a callable to apply on the values
250-
p_ids = list(ids(v) for v in argvalues)
251-
return p_ids
257+
if full_resolve:
258+
return list(ids(v) for v in argvalues)
259+
else:
260+
return ids
252261

253262

254263
def make_test_ids_from_param_values(param_names,

0 commit comments

Comments
 (0)