code: def test_finetuning_with_ckpt_path(tmpdir):
      """This test validates that generated ModelCheckpoint is pointing to the right best_model_path during test."""
      checkpoint_callback = ModelCheckpoint(
          monitor="val_loss",
          dirpath=tmpdir,
          filename="{epoch:02d}",
          save_top_k=-1,
      )
  
      class ExtendedBoringModel(BoringModel):
          def configure_optimizers(self):
              optimizer = torch.optim.SGD(
                  self.layer.parameters(), lr=0.001
              )
              lr_scheduler = torch.optim.lr_scheduler.StepLR(
                  optimizer, step_size=1
              )
              return [optimizer], [lr_scheduler]
  
          def validation_step(self, batch, batch_idx):
              loss = self.step(batch)
              self.log("val_loss", loss, on_epoch=True, prog_bar=True)
  
      model = ExtendedBoringModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_train_batches=12,
          limit_val_batches=6,
          limit_test_batches=12,
          callbacks=[checkpoint_callback],
          logger=False,
      )
      trainer.fit(model)
      assert os.listdir(tmpdir) == ["epoch=00.ckpt"]
  
      best_model_paths = [checkpoint_callback.best_model_path]
      for idx in range(3, 6):
          # load from checkpoint
          trainer = pl.Trainer(
              default_root_dir=tmpdir,
              max_epochs=idx,
              limit_train_batches=12,
              limit_val_batches=12,
              limit_test_batches=12,
              enable_progress_bar=False,
          )
          trainer.fit(model, ckpt_path=best_model_paths[-1])
          trainer.test()
          best_model_paths.append(
              trainer.checkpoint_callback.best_model_path
          )
  
      for idx, best_model_path in enumerate(best_model_paths):
          if idx == 0:
              assert best_model_path.endswith(f"epoch=0{idx}.ckpt")
          else:
              assert f"epoch={idx + 1}" in best_model_path
  
file_path: pytorch-lightning/tests/tests_pytorch/checkpointing/test_trainer_checkpoint.py
imports: import os
  from unittest import mock
  from unittest.mock import ANY, Mock
  import lightning.pytorch
  import pytest
  import torch
  from lightning.fabric.plugins import TorchCheckpointIO, XLACheckpointIO
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
label_desc: Use image node_id 1 for calling a global function with example usage: test_finetuning_with_ckpt_path(tmpdir) and returns: list,  list