code: def test_min_epochs_min_steps_global_step(
      tmpdir, limit_train_batches, min_epochs, min_steps, stop_step
  ):
      if min_steps:
          assert limit_train_batches < min_steps
  
      class TestModel(BoringModel):
          def training_step(self, batch, batch_idx):
              self.log("foo", batch_idx)
              return super().training_step(batch, batch_idx)
  
      es_callback = EarlyStopping("foo")
      trainer = Trainer(
          default_root_dir=tmpdir,
          callbacks=es_callback,
          limit_val_batches=0,
          limit_train_batches=limit_train_batches,
          min_epochs=min_epochs,
          min_steps=min_steps,
          logger=False,
          enable_checkpointing=False,
          enable_progress_bar=False,
          enable_model_summary=False,
      )
      model = TestModel()
  
      expected_epochs = max(
          math.ceil(min_steps / limit_train_batches), min_epochs
      )
      # trigger early stopping directly after the first epoch
      side_effect = [(True, "")] * expected_epochs
      with mock.patch.object(
          es_callback,
          "_evaluate_stopping_criteria",
          side_effect=side_effect,
      ):
          trainer.fit(model)
  
      assert trainer.should_stop
      # epochs continue until min steps are reached
      assert trainer.current_epoch == expected_epochs
      # steps continue until min steps are reached AND the epoch is exhausted
      assert trainer.global_step == stop_step
  
imports: import logging
  import math
  import os
  import pickle
  from typing import List, Optional
  from unittest import mock
  from unittest.mock import Mock
  import cloudpickle
  import pytest
  import torch
  from lightning.pytorch import Trainer, seed_everything
  from lightning.pytorch.callbacks import EarlyStopping, ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  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 10 for calling a global function with example usage: test_min_epochs_min_steps_global_step(tmpdir, limit_train_batches, min_epochs, min_steps, stop_step) and returns: super