code: def test_run_initialized(wandb: mock.MagicMock) -> None:
      wandb.sdk.wandb_run.Run = mock.MagicMock
  
      n_trials = 10
      wandb_kwargs = {
          "project": "optuna",
          "group": "summary",
          "job_type": "logging",
          "mode": "offline",
          "tags": ["test-tag"],
      }
  
      WeightsAndBiasesCallback(
          metric_name="mse",
          wandb_kwargs=wandb_kwargs,
          as_multirun=False,
      )
      wandb.init.assert_called_once_with(
          project="optuna",
          group="summary",
          job_type="logging",
          mode="offline",
          tags=["test-tag"],
      )
  
      wandbc = WeightsAndBiasesCallback(
          metric_name="mse", wandb_kwargs=wandb_kwargs, as_multirun=True
      )
      wandb.run = None
  
      study = optuna.create_study(direction="minimize")
      _wrapped_func = wandbc.track_in_wandb()(lambda t: 1.0)
      wandb.init.reset_mock()
      trial = study.ask()
      _wrapped_func(trial)
  
      wandb.init.assert_called_once_with(
          project="optuna",
          group="summary",
          job_type="logging",
          mode="offline",
          tags=["test-tag"],
      )
  
      wandb.init.reset_mock()
      study.optimize(
          _objective_func, n_trials=n_trials, callbacks=[wandbc]
      )
  
      wandb.init.assert_called_with(
          project="optuna",
          group="summary",
          job_type="logging",
          mode="offline",
          tags=["test-tag"],
      )
  
      assert wandb.init.call_count == n_trials
  
      wandb.init().finish.assert_called()
      assert wandb.init().finish.call_count == n_trials
  
imports: from typing import Any
  from typing import Dict
  from typing import List
  from typing import Sequence
  from typing import Tuple
  from typing import Union
  from unittest import mock
  import pytest
  import optuna
  from optuna.integration import WeightsAndBiasesCallback
label_desc: Use image node_id 3 for calling a global function with example usage: test_run_initialized(wandb) without return types