|
7 | 7 | import re |
8 | 8 | from warnings import warn |
9 | 9 |
|
10 | | -from pytest_cases import fixture |
11 | | - |
12 | 10 | try: |
13 | 11 | from typing import Union, Callable, Iterable, Any, Type, List, Tuple # noqa |
14 | 12 | except ImportError: |
|
20 | 18 | from .common_pytest_lazy_values import lazy_value |
21 | 19 | from .common_pytest import safe_isclass, MiniMetafunc |
22 | 20 |
|
| 21 | +from . import fixture |
23 | 22 | from .case_funcs_new import matches_tag_query, is_case_function, is_case_class, CaseInfo, CASE_PREFIX_FUN |
| 23 | +from .fixture__creation import check_name_available, CHANGE |
24 | 24 | from .fixture_parametrize_plus import fixture_ref, _parametrize_plus |
25 | 25 |
|
| 26 | + |
26 | 27 | THIS_MODULE = object() |
27 | 28 | """Singleton that can be used instead of a module name to indicate that the module is the current one""" |
28 | 29 |
|
@@ -280,19 +281,19 @@ def case_to_argvalues(case_fun, # type: Callable |
280 | 281 |
|
281 | 282 | host_module = import_module(case_fun.__module__) |
282 | 283 |
|
283 | | - # create a new fixture and place it on the host (note: if already done, no need to recreate it) |
284 | | - existing_fix = getattr(host_cls or host_module, case_id, None) |
285 | | - if existing_fix is None: |
286 | | - # if meta.is_parametrized: |
287 | | - # nothing to do, the parametrization marks are already there |
288 | | - new_fix = fixture(name=case_id)(case_fun) |
289 | | - setattr(host_cls or host_module, case_id, new_fix) |
290 | | - else: |
291 | | - raise NotImplementedError("We should check if this is the same or another and generate a new name in that " |
292 | | - "case") |
| 284 | + # create a new fixture and place it on the host |
| 285 | + # we have to create a unique fixture name if the fixture already exists. |
| 286 | + def name_changer(name, i): |
| 287 | + return name + '_' * i |
| 288 | + new_fix_name = check_name_available(host_cls or host_module, name=case_id, if_name_exists=CHANGE, |
| 289 | + name_changer=name_changer) |
| 290 | + # if meta.is_parametrized: |
| 291 | + # nothing to do, the parametrization marks are already there |
| 292 | + new_fix = fixture(name=new_fix_name)(case_fun) |
| 293 | + setattr(host_cls or host_module, new_fix_name, new_fix) |
293 | 294 |
|
294 | 295 | # now reference the new or existing fixture |
295 | | - argvalues_tuple = (fixture_ref(case_id),) |
| 296 | + argvalues_tuple = (fixture_ref(new_fix_name),) |
296 | 297 | return make_marked_parameter_value(argvalues_tuple, marks=case_marks) if case_marks else argvalues_tuple |
297 | 298 |
|
298 | 299 |
|
|
0 commit comments