aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py2/patches/03-limit-id.patch
blob: 5389c9290e57969763328aef3d169b1ecab09947 (plain) (blame)
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/py2/_pytest/python.py	(index)
+++ contrib/python/pytest/py2/_pytest/python.py	(working tree)
@@ -1204,6 +1204,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, parameterset, argnames, idfn, ids, item, config):
     if parameterset.id is not None:
         return parameterset.id