code: def cluster_log_manager(
      request: SubRequest,
  ) -> Iterator[Optional[ClusterLogManager]]:
      master_scheme = request.config.getoption("--master-scheme")
      master_host = request.config.getoption("--master-host")
      master_port = request.config.getoption("--master-port")
      det_version = request.config.getoption("--det-version")
      follow_local_logs = request.config.getoption(
          "--follow-local-logs"
      )
      compare_stats_enabled = not request.config.getoption(
          "--no-compare-stats"
      )
  
      config.MASTER_SCHEME = master_scheme
      config.MASTER_IP = master_host
      config.MASTER_PORT = master_port
      config.DET_VERSION = det_version
  
      if master_host == "localhost" and follow_local_logs:
          project_name = request.config.getoption(
              "--compose-project-name"
          )
          with ClusterLogManager(
              lambda: subprocess.run(
                  [
                      "det",
                      "deploy",
                      "local",
                      "logs",
                      "--cluster-name",
                      project_name,
                  ]
              )
          ) as clm:
              # Yield instead of return so that `__exit__` is called when the
              # testing session is finished.
              yield clm
      else:
          # Yield `None` so that pytest handles the no log manager case correctly.
          yield None
  
      if compare_stats_enabled:
          compare_stats()
  
imports: import json
  import subprocess
  import time
  from pathlib import Path
  from typing import Any, Callable, Dict, Iterator, Optional, cast
  import boto3
  import pytest
  from _pytest.config.argparsing import Parser
  from _pytest.fixtures import SubRequest
  from botocore import exceptions
  from determined.experimental import client
  from tests import config
  from tests.experiment import profile_test
  from tests.nightly.compute_stats import compare_stats
  from .cluster.test_users import logged_in_user
  from .cluster_log_manager import ClusterLogManager
label_desc: Use image node_id 2 for calling a global function with example usage: cluster_log_manager(request) without return types