code: def test_optimizer_step_no_closure_raises(tmpdir):
      class TestModel(BoringModel):
          def optimizer_step(
              self,
              epoch=None,
              batch_idx=None,
              optimizer=None,
              optimizer_closure=None,
              **_,
          ):
              # does not call `optimizer_closure()`
              pass
  
      model = TestModel()
      trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=1)
      with pytest.raises(
          MisconfigurationException,
          match="The closure hasn't been executed",
      ):
          trainer.fit(model)
  
      class TestModel(BoringModel):
          def configure_optimizers(self):
              class BrokenSGD(torch.optim.SGD):
                  def step(self, closure=None):
                      # forgot to pass the closure
                      return super().step()
  
              return BrokenSGD(self.layer.parameters(), lr=0.1)
  
      model = TestModel()
      trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=1)
      with pytest.raises(
          MisconfigurationException,
          match="The closure hasn't been executed",
      ):
          trainer.fit(model)
  
imports: import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
label_desc: Use image node_id 1 for calling a global function with example usage: test_optimizer_step_no_closure_raises(tmpdir) and returns: BrokenSGD, super