code: def test_comet_logger_online(comet_mock):
      """Test comet online with mocks."""
      # Test api_key given
      comet_experiment = comet_mock.Experiment
      logger = CometLogger(
          api_key="key", workspace="dummy-test", project_name="general"
      )
      _ = logger.experiment
      comet_experiment.assert_called_once_with(
          api_key="key", workspace="dummy-test", project_name="general"
      )
  
      # Test both given
      comet_experiment.reset_mock()
      logger = CometLogger(
          save_dir="test",
          api_key="key",
          workspace="dummy-test",
          project_name="general",
      )
      _ = logger.experiment
      comet_experiment.assert_called_once_with(
          api_key="key", workspace="dummy-test", project_name="general"
      )
  
      # Test already exists
      comet_existing = comet_mock.ExistingExperiment
      logger = CometLogger(
          experiment_key="test",
          experiment_name="experiment",
          api_key="key",
          workspace="dummy-test",
          project_name="general",
      )
      _ = logger.experiment
      comet_existing.assert_called_once_with(
          api_key="key",
          workspace="dummy-test",
          project_name="general",
          previous_experiment="test",
      )
      comet_existing().set_name.assert_called_once_with("experiment")
  
      # API experiment
      api = comet_mock.api.API
      CometLogger(
          api_key="key",
          workspace="dummy-test",
          project_name="general",
          rest_api_key="rest",
      )
      api.assert_called_once_with("rest")
  
imports: import os
  from unittest import mock
  from unittest.mock import DEFAULT, Mock, patch
  import pytest
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loggers import CometLogger
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from torch import tensor
label_desc: Use image node_id 2 for calling a global function with example usage: test_comet_logger_online(comet_mock) without return types