code: def test_lr_scheduler_state_updated_before_saving(
      tmpdir, every_n_train_steps, epoch_interval
  ):
      batches = 2
      max_epochs = 1
      lr, gamma = 1, 10
      trainer = Trainer(
          default_root_dir=tmpdir,
          enable_progress_bar=False,
          logger=False,
          max_epochs=max_epochs,
          limit_train_batches=batches,
          limit_val_batches=1,
          callbacks=[
              ModelCheckpoint(
                  dirpath=tmpdir,
                  every_n_train_steps=every_n_train_steps,
              )
          ],
      )
  
      class TestModel(BoringModel):
          def configure_optimizers(self):
              optimizer = torch.optim.SGD(self.parameters(), lr=lr)
              lr_scheduler = torch.optim.lr_scheduler.StepLR(
                  optimizer, step_size=1, gamma=gamma
              )
              lr_scheduler_config = {"scheduler": lr_scheduler}
              if not epoch_interval:
                  lr_scheduler_config["interval"] = "step"
              return [optimizer], [lr_scheduler_config]
  
          def on_save_checkpoint(self, checkpoint):
              lr_scheduler_config = checkpoint["lr_schedulers"][0]
              # 2 batches ran. since the lr_scheduler_config interval is `step`, the step count should be 2
              assert self.trainer.global_step == batches
              compare_to = max_epochs if epoch_interval else batches
              assert (
                  lr_scheduler_config["_step_count"] - 1 == compare_to
              )  # step count starts at 1
              assert lr_scheduler_config["_last_lr"] == [
                  lr * gamma**compare_to
              ]
              self.on_save_checkpoint_called = True
  
      model = TestModel()
      trainer.fit(model)
      assert model.on_save_checkpoint_called
  
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 23 for calling a global function with example usage: test_lr_scheduler_state_updated_before_saving(tmpdir, every_n_train_steps, epoch_interval) and returns: list,  list