code: def test_running_test_after_fitting(tmpdir):
      """Verify test() on fitted model."""
      seed_everything(42)
  
      class ModelTrainValTest(BoringModel):
          def validation_step(self, *args, **kwargs):
              output = super().validation_step(*args, **kwargs)
              self.log("val_loss", output["x"])
              return output
  
          def test_step(self, *args, **kwargs):
              output = super().test_step(*args, **kwargs)
              self.log("test_loss", output["y"])
              return output
  
      model = ModelTrainValTest()
  
      # logger file to get meta
      logger = tutils.get_default_logger(tmpdir)
  
      # logger file to get weights
      checkpoint = tutils.init_checkpoint_callback(logger)
  
      # fit model
      trainer = Trainer(
          default_root_dir=tmpdir,
          enable_progress_bar=False,
          max_epochs=2,
          limit_train_batches=0.4,
          limit_val_batches=0.2,
          limit_test_batches=0.2,
          callbacks=[checkpoint],
          logger=logger,
      )
      trainer.fit(model)
  
      assert (
          trainer.state.finished
      ), f"Training failed with {trainer.state}"
  
      trainer.test()
  
      # test we have good test accuracy
      tutils.assert_ok_model_acc(trainer, key="test_loss", thr=0.5)
  
file_path: pytorch-lightning/tests/tests_pytorch/models/test_cpu.py
imports: import os
  from unittest import mock
  import torch
  from lightning.pytorch import Trainer, seed_everything
  from lightning.pytorch.callbacks import Callback, EarlyStopping, ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  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
label_desc: Use image node_id 6 for calling a global function with example usage: test_running_test_after_fitting(tmpdir) and returns: output, output