code: def test_wandb_logger_init(wandb_mock):
      """Verify that basic functionality of wandb logger works.
  
      Wandb doesn't work well with pytest so we have to mock it out here.
  
      """
      # test wandb.init called when there is no W&B run
      wandb_mock.run = None
      logger = WandbLogger(
          name="test_name",
          save_dir="test_save_dir",
          version="test_id",
          project="test_project",
          resume="never",
      )
      logger.log_metrics({"acc": 1.0})
      wandb_mock.init.assert_called_once_with(
          name="test_name",
          dir="test_save_dir",
          id="test_id",
          project="test_project",
          resume="never",
          anonymous=None,
      )
      wandb_mock.init().log.assert_called_once_with({"acc": 1.0})
  
      # test wandb.init called with project as name if name not provided
      wandb_mock.run = None
      wandb_mock.init.reset_mock()
      WandbLogger(project="test_project").experiment
      wandb_mock.init.assert_called_once_with(
          name=None,
          dir=".",
          id=None,
          project="test_project",
          resume="allow",
          anonymous=None,
      )
  
      # test wandb.init set save_dir correctly after created
      wandb_mock.run = None
      wandb_mock.init.reset_mock()
      logger = WandbLogger()
      assert logger.save_dir is not None
      wandb_mock.run = None
      wandb_mock.init.reset_mock()
      logger = WandbLogger(save_dir=".", dir=None)
      assert logger.save_dir is not None
  
      # test wandb.init and setting logger experiment externally
      wandb_mock.run = None
      run = wandb_mock.init()
      logger = WandbLogger(experiment=run)
      assert logger.experiment
  
      # test wandb.init not called if there is a W&B run
      wandb_mock.init().log.reset_mock()
      wandb_mock.init.reset_mock()
      wandb_mock.run = wandb_mock.init()
  
      logger = WandbLogger()
      with pytest.warns(
          UserWarning, match="There is a wandb run already in progress"
      ):
          _ = logger.experiment
  
      # check that no new run is created
      with no_warning_call(
          UserWarning, match="There is a wandb run already in progress"
      ):
          _ = logger.experiment
  
      # verify default resume value
      assert logger._wandb_init["resume"] == "allow"
  
      logger.log_metrics({"acc": 1.0}, step=3)
      wandb_mock.init.assert_called_once()
      wandb_mock.init().log.assert_called_once_with(
          {"acc": 1.0, "trainer/global_step": 3}
      )
  
      # continue training on same W&B run and offset step
      logger.finalize("success")
      logger.log_metrics({"acc": 1.0}, step=6)
      wandb_mock.init().log.assert_called_with(
          {"acc": 1.0, "trainer/global_step": 6}
      )
  
      # log hyper parameters
      hparams = {"test": None, "nested": {"a": 1}, "b": [2, 3, 4]}
      logger.log_hyperparams(hparams)
      wandb_mock.init().config.update.assert_called_once_with(
          hparams, allow_val_change=True
      )
  
      # watch a model
      logger.watch("model", "log", 10, False)
      wandb_mock.init().watch.assert_called_once_with(
          "model", log="log", log_freq=10, log_graph=False
      )
  
      assert logger.version == wandb_mock.init().id
  
imports: import os
  import pickle
  from unittest import mock
  import pytest
  import yaml
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.cli import LightningCLI
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loggers import WandbLogger
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning_utilities.test.warning import no_warning_call
label_desc: Use image node_id 2 for calling a global function with example usage: test_wandb_logger_init(wandb_mock) without return types