|
6 | 6 | import sys
|
7 | 7 | import warnings
|
8 | 8 | from collections import Counter
|
| 9 | +from collections import defaultdict |
9 | 10 | from collections.abc import Sequence
|
10 | 11 | from functools import partial
|
11 | 12 | from textwrap import dedent
|
@@ -1190,14 +1191,23 @@ def idmaker(argnames, parametersets, idfn=None, ids=None, config=None, item=None
|
1190 | 1191 | _idvalset(valindex, parameterset, argnames, idfn, ids, config=config, item=item)
|
1191 | 1192 | for valindex, parameterset in enumerate(parametersets)
|
1192 | 1193 | ]
|
1193 |
| - if len(set(ids)) != len(ids): |
1194 |
| - # The ids are not unique |
1195 |
| - duplicates = [testid for testid in ids if ids.count(testid) > 1] |
1196 |
| - counters = Counter() |
1197 |
| - for index, testid in enumerate(ids): |
1198 |
| - if testid in duplicates: |
1199 |
| - ids[index] = testid + str(counters[testid]) |
1200 |
| - counters[testid] += 1 |
| 1194 | + |
| 1195 | + # All IDs must be unique! |
| 1196 | + unique_ids = set(ids) |
| 1197 | + if len(unique_ids) != len(ids): |
| 1198 | + |
| 1199 | + # Record the number of occurrences of each test ID |
| 1200 | + test_id_counts = Counter(ids) |
| 1201 | + |
| 1202 | + # Map the test ID to its next suffix |
| 1203 | + test_id_suffixes = defaultdict(int) |
| 1204 | + |
| 1205 | + # Suffix non-unique IDs to make them unique |
| 1206 | + for index, test_id in enumerate(ids): |
| 1207 | + if test_id_counts[test_id] > 1: |
| 1208 | + ids[index] = "{}{}".format(test_id, test_id_suffixes[test_id]) |
| 1209 | + test_id_suffixes[test_id] += 1 |
| 1210 | + |
1201 | 1211 | return ids
|
1202 | 1212 |
|
1203 | 1213 |
|
|
0 commit comments