--- contrib/python/pytest/py3/_pytest/python.py	(index)
+++ contrib/python/pytest/py3/_pytest/python.py	(working tree)
@@ -991,7 +991,7 @@ class IdMaker:
         The counter suffix is appended only in case a string wouldn't be unique
         otherwise.
         """
-        resolved_ids = list(self._resolve_ids())
+        resolved_ids = list(self._limit_ids(self._resolve_ids(), limit=500))
         # All IDs must be unique!
         if len(resolved_ids) != len(set(resolved_ids)):
             # Record the number of occurrences of each ID.
@@ -1005,6 +1005,19 @@ class IdMaker:
                     id_suffixes[id] += 1
         return resolved_ids
 
+    def _limit_ids(self, ids, limit=500):
+        prefix_count = {}
+        limit -= 6
+        assert limit > 0
+
+        for idval in ids:
+            if len(idval) > limit:
+                prefix = idval[:limit]
+                idx = prefix_count.get(prefix, -1) + 1
+                prefix_count[prefix] = idx
+                idval = "{}-{}".format(prefix, idx)
+            yield idval
+
     def _resolve_ids(self) -> Iterable[str]:
         """Resolve IDs for all ParameterSets (may contain duplicates)."""
         for idx, parameterset in enumerate(self.parametersets):