Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized renaming of test parameter ids #6350

Merged
merged 1 commit into from Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -235,6 +235,7 @@ Samuele Pedroni
Sankt Petersbug
Segev Finer
Serhii Mozghovyi
Seth Junot
Simon Gomizelj
Skylar Downes
Srinivas Reddy Thatiparthy
Expand Down
1 change: 1 addition & 0 deletions changelog/6350.trivial.rst
@@ -0,0 +1 @@
Optimized automatic renaming of test parameter IDs.
26 changes: 18 additions & 8 deletions src/_pytest/python.py
Expand Up @@ -6,6 +6,7 @@
import sys
import warnings
from collections import Counter
from collections import defaultdict
from collections.abc import Sequence
from functools import partial
from textwrap import dedent
Expand Down Expand Up @@ -1190,14 +1191,23 @@ def idmaker(argnames, parametersets, idfn=None, ids=None, config=None, item=None
_idvalset(valindex, parameterset, argnames, idfn, ids, config=config, item=item)
for valindex, parameterset in enumerate(parametersets)
]
if len(set(ids)) != len(ids):
# The ids are not unique
duplicates = [testid for testid in ids if ids.count(testid) > 1]
counters = Counter()
for index, testid in enumerate(ids):
if testid in duplicates:
ids[index] = testid + str(counters[testid])
counters[testid] += 1

# All IDs must be unique!
unique_ids = set(ids)
if len(unique_ids) != len(ids):

# Record the number of occurrences of each test ID
test_id_counts = Counter(ids)

# Map the test ID to its next suffix
test_id_suffixes = defaultdict(int)

# Suffix non-unique IDs to make them unique
for index, test_id in enumerate(ids):
if test_id_counts[test_id] > 1:
ids[index] = "{}{}".format(test_id, test_id_suffixes[test_id])
test_id_suffixes[test_id] += 1

return ids


Expand Down