|
42 | 42 |
|
43 | 43 | from pytest_cases.case_funcs import _GENERATOR_FIELD, CASE_TAGS_FIELD |
44 | 44 | from pytest_cases.common import yield_fixture, get_pytest_parametrize_marks, get_test_ids_from_param_values, \ |
45 | | - is_marked_parameter_value, get_marked_parameter_marks, get_marked_parameter_values, make_marked_parameter_value, \ |
46 | | - get_pytest_marks_on_function |
| 45 | + make_marked_parameter_value, get_pytest_marks_on_function, extract_parameterset_info |
47 | 46 |
|
48 | 47 |
|
49 | 48 | class CaseDataGetter(six.with_metaclass(ABCMeta)): |
@@ -271,58 +270,49 @@ def pytest_fixture_plus(scope="function", |
271 | 270 | return fix_creator(scope=scope, autouse=autouse, **kwargs)(fixture_func) |
272 | 271 |
|
273 | 272 | # (2) create the huge "param" containing all params combined |
274 | | - # --loop |
| 273 | + # --loop (use the same order to get it right) |
275 | 274 | params_names_or_name_combinations = [] |
276 | 275 | params_values = [] |
277 | 276 | params_ids = [] |
278 | 277 | params_marks = [] |
279 | | - # -- use same order to get it right |
280 | | - for m in parametrizer_marks: |
281 | | - # check what the mark specifies in terms of parameters |
282 | | - if len(m.param_names) < 1: |
| 278 | + for pmark in parametrizer_marks: |
| 279 | + # check number of parameter names in this parameterset |
| 280 | + if len(pmark.param_names) < 1: |
283 | 281 | raise ValueError("Fixture function '%s' decorated with '@pytest_fixture_plus' has an empty parameter " |
284 | 282 | "name in a @pytest.mark.parametrize mark") |
285 | 283 |
|
| 284 | + # remember |
| 285 | + params_names_or_name_combinations.append(pmark.param_names) |
| 286 | + |
| 287 | + # extract all parameters that have a specific configuration (pytest.param()) |
| 288 | + _pids, _pmarks, _pvalues = extract_parameterset_info(pmark.param_names, pmark) |
| 289 | + |
| 290 | + # Create the proper id for each test |
| 291 | + if pmark.param_ids is not None: |
| 292 | + # overridden at global pytest.mark.parametrize level - this takes precedence. |
| 293 | + try: # an explicit list of ids ? |
| 294 | + paramids = list(pmark.param_ids) |
| 295 | + except TypeError: # a callable to apply on the values |
| 296 | + paramids = list(pmark.param_ids(v) for v in _pvalues) |
286 | 297 | else: |
287 | | - # fix bug: pytest does not strip the param names when they come from a coma-separated "arg1, arg2" |
288 | | - _pnames = tuple(name.strip() for name in m.param_names) |
289 | | - |
290 | | - # remember |
291 | | - params_names_or_name_combinations.append(_pnames) |
292 | | - _pvalues = [] |
293 | | - _pmarks = [] |
294 | | - for v in m.param_values: |
295 | | - if is_marked_parameter_value(v): |
296 | | - marks = get_marked_parameter_marks(v) |
297 | | - vals = get_marked_parameter_values(v) |
298 | | - if len(vals) != len(_pnames): |
299 | | - raise ValueError("Internal error - unsupported pytest parametrization+mark combination. Please " |
300 | | - "report this issue") |
301 | | - _pmarks.append(marks) # there might be several |
302 | | - if len(vals) == 1: |
303 | | - _pvalues.append(vals[0]) |
304 | | - else: |
305 | | - _pvalues.append(vals) |
306 | | - else: |
307 | | - _pmarks.append(None) |
308 | | - _pvalues.append(v) |
309 | | - params_values.append(tuple(_pvalues)) |
310 | | - params_marks.append(tuple(_pmarks)) |
311 | | - if m.param_ids is not None: |
312 | | - try: |
313 | | - paramids = tuple(m.param_ids) |
314 | | - except TypeError: |
315 | | - paramids = tuple(m.param_ids(v) for v in _pvalues) |
316 | | - else: |
317 | | - paramids = get_test_ids_from_param_values(_pnames, _pvalues) |
318 | | - params_ids.append(paramids) |
| 298 | + # default: values-based... |
| 299 | + paramids = get_test_ids_from_param_values(pmark.param_names, _pvalues) |
| 300 | + # ...but local pytest.param takes precedence |
| 301 | + for i, _id in enumerate(_pids): |
| 302 | + if _id is not None: |
| 303 | + paramids[i] = _id |
| 304 | + |
| 305 | + # Finally store the ids, marks, and values for this parameterset |
| 306 | + params_ids.append(paramids) |
| 307 | + params_marks.append(tuple(_pmarks)) |
| 308 | + params_values.append(tuple(_pvalues)) |
319 | 309 |
|
320 | 310 | # (3) generate the ids and values, possibly reapplying marks |
321 | 311 | if len(params_names_or_name_combinations) == 1: |
322 | 312 | # we can simplify - that will be more readable |
323 | | - final_values = list(params_values[0]) |
324 | 313 | final_ids = params_ids[0] |
325 | 314 | final_marks = params_marks[0] |
| 315 | + final_values = list(params_values[0]) |
326 | 316 |
|
327 | 317 | # reapply the marks |
328 | 318 | for i, marks in enumerate(final_marks): |
|
0 commit comments