03-limit-id.patch 1.1 KB

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