code: def test_restarting_mid_epoch_raises_warning(
      tmpdir, stop_in_the_middle, model_cls
  ):
      """Test that a warning is raised if training is restarted from mid-epoch."""
      limit_train_batches = 8
      trainer_kwargs = {
          "default_root_dir": tmpdir,
          "limit_train_batches": limit_train_batches,
          "limit_val_batches": 0,
          "enable_progress_bar": False,
          "enable_model_summary": False,
      }
      trainer = Trainer(max_epochs=1, **trainer_kwargs)
      model = model_cls(
          limit_train_batches // 2 if stop_in_the_middle else -1
      )
  
      if stop_in_the_middle:
          with pytest.raises(CustomException):
              trainer.fit(model)
      else:
          trainer.fit(model)
  
      ckpt_path = str(tmpdir / "resume.ckpt")
      trainer.save_checkpoint(ckpt_path)
  
      trainer = Trainer(max_epochs=2, **trainer_kwargs)
      model.stop_batch_idx = -1
  
      context_manager = (
          pytest.warns if stop_in_the_middle else no_warning_call
      )
      with context_manager(
          UserWarning, match="resuming from a checkpoint that ended"
      ):
          trainer.fit(model, ckpt_path=ckpt_path)
  
      if stop_in_the_middle:
          trainer = Trainer(max_epochs=2, **trainer_kwargs)
          with pytest.warns(
              UserWarning, match="resuming from a checkpoint that ended"
          ):
              trainer.fit(model, ckpt_path=ckpt_path)
  
imports: import glob
  import logging
  import os
  import pickle
  from copy import deepcopy
  from typing import Generic, Mapping, TypeVar
  import cloudpickle
  import pytest
  import torch
  from lightning.fabric import seed_everything
  from lightning.pytorch import Callback, Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.states import TrainerFn
  from lightning_utilities.test.warning import no_warning_call
  from torch import Tensor
  import tests_pytorch.helpers.pipelines
  import tests_pytorch.helpers.utils
  from tests_pytorch.helpers.datamodules import ClassifDataModule
  from tests_pytorch.helpers.runif import RunIf
  from tests_pytorch.helpers.simple_models import ClassificationModel
  from tests_pytorch.loops.test_loops import CustomException
label_desc: Use image node_id 15 for calling a global function with example usage: test_restarting_mid_epoch_raises_warning(tmpdir, stop_in_the_middle, model_cls) without return types