code: def test_invalid_optimizer_in_scheduler(tmpdir):
      """Test exception when optimizer attached to lr_schedulers wasn't returned."""
  
      class InvalidOptimizerModel(BoringModel):
          def configure_optimizers(self):
              opt1 = optim.SGD(self.layer.parameters(), lr=0.1)
              opt2 = optim.SGD(self.layer.parameters(), lr=0.1)
              lr_scheduler = optim.lr_scheduler.StepLR(
                  opt2, step_size=1
              )
              return [opt1], [lr_scheduler]
  
      model = InvalidOptimizerModel()
      trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=True)
      with pytest.raises(
          MisconfigurationException,
          match="attached with an optimizer that wasn't returned",
      ):
          trainer.fit(model)
  
imports: from unittest import mock
  from unittest.mock import call
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.core.optimizer import _configure_optimizers, _configure_schedulers_automatic_opt, _init_optimizers_and_lr_schedulers
  from lightning.pytorch.demos.boring_classes import BoringDataModule, BoringModel
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.types import LRSchedulerConfig
  from torch import optim
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 19 for calling a global function with example usage: test_invalid_optimizer_in_scheduler(tmpdir) and returns: list,  list