code: def test_autologging_integrations_use_safe_patch_for_monkey_patching(
      integration,
  ):
      with mock.patch(
          "mlflow.utils.gorilla.apply", wraps=gorilla.apply
      ) as gorilla_mock, mock.patch(
          integration.__name__ + ".safe_patch", wraps=safe_patch
      ) as safe_patch_mock:
          # In `mlflow.xgboost.autolog()` and `mlflow.lightgbm.autolog()`,
          # we enable autologging for XGBoost and LightGBM sklearn models
          # using `mlflow.sklearn._autolog()`. So besides `safe_patch` calls in
          # `autolog()`, we need to count additional `safe_patch` calls
          # in sklearn autologging routine as well.
          if integration.__name__ in [
              "mlflow.xgboost",
              "mlflow.lightgbm",
          ]:
              with mock.patch(
                  "mlflow.sklearn.safe_patch", wraps=safe_patch
              ) as sklearn_safe_patch_mock:
                  integration.autolog(disable=False)
                  safe_patch_call_count = (
                      safe_patch_mock.call_count
                      + sklearn_safe_patch_mock.call_count
                  )
  
                  # Assert autolog integrations use the fluent API for run management. This is to
                  # ensure certain fluent API methods like mlflow.last_active_run behaves as expected.
                  assert any(
                      kwargs["manage_run"]
                      for _, kwargs in sklearn_safe_patch_mock.call_args_list
                      if "manage_run" in kwargs
                  )
          else:
              integration.autolog(disable=False)
              safe_patch_call_count = safe_patch_mock.call_count
  
          if integration.__name__ != "mlflow.spark":
              # Assert autolog integrations use the fluent API for run management. This is to
              # ensure certain fluent API methods like mlflow.last_active_run behaves as expected.
              assert any(
                  kwargs["manage_run"]
                  for _, kwargs in safe_patch_mock.call_args_list
                  if "manage_run" in kwargs
              )
          assert safe_patch_call_count > 0
          # `safe_patch` leverages `gorilla.apply` in its implementation. Accordingly, we expect
          # that the total number of `gorilla.apply` calls to be equivalent to the number of
          # `safe_patch` calls. This verifies that autologging integrations are leveraging
          # `safe_patch`, rather than calling `gorilla.apply` directly (which does not provide
          # exception safety properties)
          assert safe_patch_call_count == gorilla_mock.call_count
  
imports: import importlib
  import logging
  import sys
  import warnings
  from concurrent.futures import ThreadPoolExecutor
  from io import StringIO
  from itertools import permutations
  from unittest import mock
  import pytest
  import mlflow
  from mlflow import MlflowClient
  from mlflow.utils import gorilla
  from mlflow.utils.autologging_utils import autologging_is_disabled, get_autologging_config, safe_patch
  from tests.autologging.fixtures import reset_stderr, test_mode_off
label_desc: Use image node_id 5 for calling a global function with example usage: test_autologging_integrations_use_safe_patch_for_monkey_patching(integration) without return types