code: def _fit_model(
      tmpdir,
      should_signal,
      val_check_interval,
      failure_on_step,
      failure_on_training,
      on_last_batch,
      status=None,
  ):
      seed_everything(42)
      model = TestAutoRestartModelUnderSignal(
          should_signal,
          failure_on_step,
          failure_on_training,
          on_last_batch,
      )
  
      class MyTestCallback(Callback):
          raising_function = None
  
          def on_exception(self, trainer, pl_module, exception):
              if isinstance(exception, SIGTERMException):
                  caller = inspect.trace()[-1]
                  class_name = (
                      caller[0].f_locals["self"].__class__.__name__
                  )
                  self.raising_method = (
                      f"{class_name}:{caller.function}"
                  )
  
      test_callback = MyTestCallback()
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_train_batches=4,
          limit_val_batches=4,
          val_check_interval=val_check_interval,
          num_sanity_val_steps=0,
          callbacks=[test_callback, OnExceptionCheckpoint(tmpdir)],
      )
      if should_signal:
          with pytest.raises(SIGTERMException):
              trainer.fit(model)
          assert test_callback.raising_method == status
      else:
          trainer.fit(model)
      assert trainer.received_sigterm == should_signal
  
      return model
  
imports: import inspect
  import pytest
  from lightning.fabric.utilities.seed import seed_everything
  from lightning.pytorch import Callback, Trainer
  from lightning.pytorch.callbacks import OnExceptionCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.utilities.exceptions import SIGTERMException
  from torch.utils.data.dataloader import DataLoader
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 1 for calling a global function with example usage: _fit_model(tmpdir, should_signal, val_check_interval, failure_on_step, failure_on_training, on_last_batch, status) and returns: model