-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrize
Description
make_unique_parameterset_ids() goes to some lengths to create a unique set of parameter ids when there are duplicates:
Lines 891 to 926 in 9913ced
| def make_unique_parameterset_ids(self) -> list[str | _HiddenParam]: | |
| """Make a unique identifier for each ParameterSet, that may be used to | |
| identify the parametrization in a node ID. | |
| Format is <prm_1_token>-...-<prm_n_token>[counter], where prm_x_token is | |
| - user-provided id, if given | |
| - else an id derived from the value, applicable for certain types | |
| - else <argname><parameterset index> | |
| The counter suffix is appended only in case a string wouldn't be unique | |
| otherwise. | |
| """ | |
| resolved_ids = list(self._resolve_ids()) | |
| # All IDs must be unique! | |
| if len(resolved_ids) != len(set(resolved_ids)): | |
| # Record the number of occurrences of each ID. | |
| id_counts = Counter(resolved_ids) | |
| # Map the ID to its next suffix. | |
| id_suffixes: dict[str, int] = defaultdict(int) | |
| # Suffix non-unique IDs to make them unique. | |
| for index, id in enumerate(resolved_ids): | |
| if id_counts[id] > 1: | |
| if id is HIDDEN_PARAM: | |
| self._complain_multiple_hidden_parameter_sets() | |
| suffix = "" | |
| if id and id[-1].isdigit(): | |
| suffix = "_" | |
| new_id = f"{id}{suffix}{id_suffixes[id]}" | |
| while new_id in set(resolved_ids): | |
| id_suffixes[id] += 1 | |
| new_id = f"{id}{suffix}{id_suffixes[id]}" | |
| resolved_ids[index] = new_id | |
| id_suffixes[id] += 1 | |
| assert len(resolved_ids) == len(set(resolved_ids)), ( | |
| f"Internal error: {resolved_ids=}" | |
| ) | |
| return resolved_ids |
...but in some cases, we'd prefer to raise an error instead of trying to make this work. (for example, when plugins are doing fancy collection tricks and then a subsequent run tries to select a subset of those nodeids)
Metadata
Metadata
Assignees
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrize