code: def test_mlflow_logger_finalize_when_exception(mlflow_mock):
      logger = MLFlowLogger("test")
  
      # Pretend we are on the main process and failing
      assert logger._mlflow_client
      assert not logger._initialized
      logger.finalize("failed")
      logger.experiment.set_terminated.assert_not_called()
  
      # Pretend we are in a worker process and failing
      _ = logger.experiment
      assert logger._initialized
      logger.finalize("failed")
      logger.experiment.set_terminated.assert_called_once_with(
          logger.run_id, "FAILED"
      )
  
imports: import os
  from unittest import mock
  from unittest.mock import MagicMock, Mock
  import pytest
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loggers.mlflow import _MLFLOW_AVAILABLE, MLFlowLogger, _get_resolve_tags
label_desc: Use image node_id 13 for calling a global function with example usage: test_mlflow_logger_finalize_when_exception(mlflow_mock) without return types