code: def test_dataloader_batch_size_updated_on_failure(
      _, tmpdir, scale_method, expected_batch_size
  ):
      class CustomBatchSizeModel(BatchSizeModel):
          def training_step(self, *_, **__):
              if self.batch_size > 100:
                  raise RuntimeError
  
          def train_dataloader(self):
              return DataLoader(
                  RandomDataset(32, 1000), batch_size=self.batch_size
              )
  
      model = CustomBatchSizeModel(batch_size=16)
      model.validation_step = None
      scale_batch_size_kwargs = {
          "max_trials": 10,
          "steps_per_trial": 1,
          "init_val": 500,
          "mode": scale_method,
      }
  
      trainer = Trainer(default_root_dir=tmpdir, max_epochs=2)
      tuner = Tuner(trainer)
      new_batch_size = tuner.scale_batch_size(
          model, **scale_batch_size_kwargs
      )
      assert new_batch_size == model.batch_size
      assert new_batch_size == expected_batch_size
      assert trainer.train_dataloader.batch_size == expected_batch_size
  
imports: import logging
  import os
  from copy import deepcopy
  from unittest.mock import patch
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder
  from lightning.pytorch.demos.boring_classes import BoringDataModule, BoringModel, RandomDataset
  from lightning.pytorch.tuner.tuning import Tuner
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning_utilities.test.warning import no_warning_call
  from torch.utils.data import DataLoader
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 20 for calling a global function with example usage: test_dataloader_batch_size_updated_on_failure(_, tmpdir, scale_method, expected_batch_size) and returns: DataLoader