code: def pytest_terminal_summary(
      terminalreporter, exitstatus, config=None
  ):
      pwd = os.path.realpath(os.curdir)
  
      def cut_path(path):
          if path.startswith(pwd):
              path = path[len(pwd) + 1 :]
          if "/site-packages/" in path:
              path = path.split("/site-packages/")[1]
          return path
  
      def format_test_function_location(item):
          return f"{item.location[0]}::{item.location[2]}:{item.location[1]}"
  
      yield
  
      if captured_warnings:
          print(
              "\n ======================== Warning summary =============================\n"
          )
          print(
              f"   The tests generated {sum(captured_warnings_count.values())} warnings."
          )
          print(
              f"   After removing duplicates, {len(captured_warnings.values())}  of them remained."
          )
          print(f"   They are stored in {warning_output_path} file.")
          print(
              "\n ======================================================================\n"
          )
          warnings_as_json = []
  
          for warning in captured_warnings.values():
              serialized_warning = {
                  x: str(getattr(warning.message, x))
                  for x in dir(warning.message)
                  if not x.startswith("__")
              }
  
              serialized_warning.update(
                  {
                      "path": cut_path(warning.filename),
                      "lineno": warning.lineno,
                      "count": 1,
                      "warning_message": str(warning.message),
                  }
              )
  
              # How we format the warnings: pylint parseable format
              # {path}:{line}: [{msg_id}({symbol}), {obj}] {msg}
              # Always:
              # {path}:{line}: [W0513(warning), ] {msg}
  
              if "with_traceback" in serialized_warning:
                  del serialized_warning["with_traceback"]
              warnings_as_json.append(serialized_warning)
  
          with warning_output_path.open("w") as f:
              for i in warnings_as_json:
                  f.write(
                      f'{i["path"]}:{i["lineno"]}: [W0513(warning), ] {i["warning_message"]}'
                  )
                  f.write("\n")
      else:
          # nothing, clear file
          with warning_output_path.open("w") as f:
              pass
  
imports: from __future__ import annotations
  import json
  import os
  import platform
  import subprocess
  import sys
  import warnings
  from contextlib import ExitStack, suppress
  from datetime import datetime, timedelta
  from pathlib import Path
  from typing import TYPE_CHECKING
  import pytest
  import time_machine
  from itsdangerous import URLSafeSerializer
label_desc: Use image node_id 42 for calling a global function with example usage: pytest_terminal_summary(terminalreporter, exitstatus, config) and returns: path, item, str, item, str, item