1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
--- contrib/python/pytest/py3/_pytest/python.py (index)
+++ contrib/python/pytest/py3/_pytest/python.py (working tree)
@@ -1339,6 +1339,33 @@ def _idval(val, argname, idx, idfn, item, config):
return str(argname) + str(idx)
+def limit_idval(limit):
+ import functools
+
+ names = {}
+ limit -= 6
+ assert limit > 0
+
+ def decorator(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kw):
+ idval = func(*args, **kw)
+ if len(idval) > limit:
+ prefix = idval[:limit]
+ # There might be same prefix for the different test cases - take item into account
+ name = "{}-{}".format(kw.get('item', ''), prefix)
+ idx = names.setdefault(name, -1) + 1
+ names[name] = idx
+ idval = "{}-{}".format(prefix, idx)
+ return idval
+
+ return wrapper
+
+ return decorator
+
+
+# XXX limit testnames in the name of sanity and readability
+@limit_idval(limit=500)
def _idvalset(
idx: int,
parameterset: ParameterSet,
|