03-limit-id.patch 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. --- contrib/python/pytest/py3/_pytest/python.py (index)
  2. +++ contrib/python/pytest/py3/_pytest/python.py (working tree)
  3. @@ -991,7 +991,7 @@ class IdMaker:
  4. The counter suffix is appended only in case a string wouldn't be unique
  5. otherwise.
  6. """
  7. - resolved_ids = list(self._resolve_ids())
  8. + resolved_ids = list(self._limit_ids(self._resolve_ids(), limit=500))
  9. # All IDs must be unique!
  10. if len(resolved_ids) != len(set(resolved_ids)):
  11. # Record the number of occurrences of each ID.
  12. @@ -1005,6 +1005,19 @@ class IdMaker:
  13. id_suffixes[id] += 1
  14. return resolved_ids
  15. + def _limit_ids(self, ids, limit=500):
  16. + prefix_count = {}
  17. + limit -= 6
  18. + assert limit > 0
  19. +
  20. + for idval in ids:
  21. + if len(idval) > limit:
  22. + prefix = idval[:limit]
  23. + idx = prefix_count.get(prefix, -1) + 1
  24. + prefix_count[prefix] = idx
  25. + idval = "{}-{}".format(prefix, idx)
  26. + yield idval
  27. +
  28. def _resolve_ids(self) -> Iterable[str]:
  29. """Resolve IDs for all ParameterSets (may contain duplicates)."""
  30. for idx, parameterset in enumerate(self.parametersets):