code: def test_prediction_loop_stores_predictions(tmp_path):
      class MyModel(BoringModel):
          def predict_step(self, batch, batch_idx):
              return batch_idx
  
      model = MyModel()
      trainer = Trainer(
          default_root_dir=tmp_path,
          limit_predict_batches=2,
          logger=False,
          enable_progress_bar=False,
          enable_model_summary=False,
      )
      predictions = trainer.predict(model, return_predictions=True)
      assert predictions == [0, 1]
      # the predictions are still available
      assert trainer.predict_loop.predictions == predictions
  
      trainer = Trainer(
          default_root_dir=tmp_path,
          limit_predict_batches=2,
          logger=False,
          enable_progress_bar=False,
          enable_model_summary=False,
      )
      predictions = trainer.predict(model, return_predictions=False)
      assert predictions is None
      assert trainer.predict_loop.predictions == []
  
file_path: pytorch-lightning/tests/tests_pytorch/loops/test_prediction_loop.py
imports: import itertools
  import pytest
  from lightning.pytorch import LightningModule, Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.overrides.distributed import _IndexBatchSamplerWrapper
  from torch.utils.data import DataLoader, DistributedSampler, SequentialSampler
label_desc: Use image node_id 1 for calling a global function with example usage: test_prediction_loop_stores_predictions(tmp_path) and returns: batch_idx