code: def test_comet_logger_manual_experiment_key(comet_mock):
      """Test that Comet Logger respects manually set COMET_EXPERIMENT_KEY."""
      api_key = "key"
      experiment_key = "96346da91469407a85641afe5766b554"
  
      instantiation_environ = {}
  
      def save_os_environ(*args, **kwargs):
          nonlocal instantiation_environ
          instantiation_environ = os.environ.copy()
  
          return DEFAULT
  
      comet_experiment = comet_mock.Experiment
      comet_experiment.side_effect = save_os_environ
  
      # Test api_key given
      with patch.dict(
          os.environ, {"COMET_EXPERIMENT_KEY": experiment_key}
      ):
          logger = CometLogger(api_key=api_key)
          assert logger.version == experiment_key
          assert logger._experiment is None
  
          _ = logger.experiment
          comet_experiment.assert_called_once_with(
              api_key=api_key, project_name=None
          )
  
      assert (
          instantiation_environ["COMET_EXPERIMENT_KEY"]
          == experiment_key
      )
  
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 5 for calling a global function with example usage: test_comet_logger_manual_experiment_key(comet_mock) and returns: DEFAULT