code: def summarize_test_cases(
      test_cases: List[Dict[str, Any]]
  ) -> List[Dict[str, Any]]:
      """Group test cases by classname, file, and job_id. We perform the aggregation
      manually instead of using the `test-suite` XML tag because xmlrunner does
      not produce reliable output for it.
      """
  
      def get_key(test_case: Dict[str, Any]) -> Any:
          return (
              test_case.get("file"),
              test_case.get("classname"),
              test_case["job_id"],
              test_case["workflow_id"],
              test_case["workflow_run_attempt"],
              # [see: invoking file]
              test_case["invoking_file"],
          )
  
      def init_value(test_case: Dict[str, Any]) -> Dict[str, Any]:
          return {
              "file": test_case.get("file"),
              "classname": test_case.get("classname"),
              "job_id": test_case["job_id"],
              "workflow_id": test_case["workflow_id"],
              "workflow_run_attempt": test_case["workflow_run_attempt"],
              # [see: invoking file]
              "invoking_file": test_case["invoking_file"],
              "tests": 0,
              "failures": 0,
              "errors": 0,
              "skipped": 0,
              "successes": 0,
              "time": 0.0,
          }
  
      ret = {}
      for test_case in test_cases:
          key = get_key(test_case)
          if key not in ret:
              ret[key] = init_value(test_case)
  
          ret[key]["tests"] += 1
  
          if "failure" in test_case:
              ret[key]["failures"] += 1
          elif "error" in test_case:
              ret[key]["errors"] += 1
          elif "skipped" in test_case:
              ret[key]["skipped"] += 1
          else:
              ret[key]["successes"] += 1
  
          ret[key]["time"] += test_case["time"]
      return list(ret.values())
  
file_path: pytorch/tools/stats/upload_test_stats.py
imports: import argparse
  import os
  import sys
  import xml.etree.ElementTree
  from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import Any, Dict, List, Optional
  from tools.stats.upload_stats_lib import download_gha_artifacts, download_s3_artifacts, unzip, upload_workflow_stats_to_s3
label_desc: Use image node_id 6 for calling a global function with example usage: summarize_test_cases(test_cases) and returns: list, test_case,  test_case,  test_case,  test_case,  test_case,  test_case, dict