code: def trace_sql(request):
      from tests.test_utils.perf.perf_kit.sqlalchemy import (  # isort: skip
          count_queries,
          trace_queries,
      )
  
      """Displays queries from the tests to console."""
      trace_sql_option = request.config.option.trace_sql
      if not trace_sql_option:
          yield
          return
  
      terminal_reporter = request.config.pluginmanager.getplugin(
          "terminalreporter"
      )
      # if no terminal reporter plugin is present, nothing we can do here;
      # this can happen when this function executes in a worker node
      # when using pytest-xdist, for example
      if terminal_reporter is None:
          yield
          return
  
      columns = [col.strip() for col in trace_sql_option.split(",")]
  
      def pytest_print(text):
          return terminal_reporter.write_line(text)
  
      with ExitStack() as exit_stack:
          if columns == ["num"]:
              # It is very unlikely that the user wants to display only numbers, but probably
              # the user just wants to count the queries.
              exit_stack.enter_context(
                  count_queries(print_fn=pytest_print)
              )
          elif any(
              c in columns
              for c in ["time", "trace", "sql", "parameters"]
          ):
              exit_stack.enter_context(
                  trace_queries(
                      display_num="num" in columns,
                      display_time="time" in columns,
                      display_trace="trace" in columns,
                      display_sql="sql" in columns,
                      display_parameters="parameters" in columns,
                      print_fn=pytest_print,
                  )
              )
  
          yield
  
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 5 for calling a global function with example usage: trace_sql(request) and returns: terminal_reporter