code: def test_lightning_optimizer_automatic_optimization_optimizer_step(
      tmpdir,
  ):
      """Test overriding step works in automatic_optimization."""
  
      class TestModel(BoringModel):
          def optimizer_step(
              self, epoch, batch_idx, optimizer, optimizer_closure, **_
          ):
              assert isinstance(optimizer_closure, Closure)
              # zero_grad is called inside the closure
              optimizer_closure()
              # not passing the closure to the optimizer because step is mocked
              if batch_idx % 2 == 0:
                  optimizer.step()
  
          def configure_optimizers(self):
              optimizer_1 = torch.optim.SGD(
                  self.layer.parameters(), lr=0.1
              )
              lr_scheduler = torch.optim.lr_scheduler.StepLR(
                  optimizer_1, step_size=1
              )
              return [optimizer_1], [lr_scheduler]
  
      model = TestModel()
  
      limit_train_batches = 8
      trainer = Trainer(
          default_root_dir=tmpdir,
          limit_train_batches=limit_train_batches,
          limit_val_batches=1,
          max_epochs=1,
          enable_model_summary=False,
      )
  
      with patch.multiple(
          torch.optim.SGD, zero_grad=DEFAULT, step=DEFAULT
      ) as sgd:
          trainer.fit(model)
  
      assert sgd["step"].call_count == limit_train_batches // 2
      assert sgd["zero_grad"].call_count == limit_train_batches
  
imports: from copy import deepcopy
  from unittest.mock import DEFAULT, Mock, patch
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.core.optimizer import LightningOptimizer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loops.optimization.automatic import Closure
  from lightning.pytorch.tuner.tuning import Tuner
  from torch.optim import SGD, Adam, Optimizer
label_desc: Use image node_id 7 for calling a global function with example usage: test_lightning_optimizer_automatic_optimization_optimizer_step(tmpdir) and returns: list,  list