code: def test_tensorboard_finalize(monkeypatch, tmp_path):
      """Test that the SummaryWriter closes in finalize."""
      if _TENSORBOARD_AVAILABLE:
          import torch.utils.tensorboard as tb
      else:
          import tensorboardX as tb
  
      monkeypatch.setattr(tb, "SummaryWriter", Mock())
      logger = TensorBoardLogger(root_dir=tmp_path)
      assert logger._experiment is None
      logger.finalize("any")
  
      # no log calls, no experiment created -> nothing to flush
      logger.experiment.assert_not_called()
  
      logger = TensorBoardLogger(root_dir=tmp_path)
      logger.log_metrics(
          {"flush_me": 11.1}
      )  # trigger creation of an experiment
      logger.finalize("any")
  
      # finalize flushes to experiment directory
      logger.experiment.flush.assert_called()
      logger.experiment.close.assert_called()
  
imports: import logging
  import os
  from argparse import Namespace
  from unittest import mock
  from unittest.mock import Mock
  import numpy
  import pytest
  import torch
  from lightning.fabric.loggers import TensorBoardLogger
  from lightning.fabric.loggers.tensorboard import _TENSORBOARD_AVAILABLE
  from lightning.fabric.wrappers import _FabricModule
  from tests_fabric.test_fabric import BoringModel
label_desc: Use image node_id 13 for calling a global function with example usage: test_tensorboard_finalize(monkeypatch, tmp_path) without return types