code: def test_max_epochs_not_set_warning():
      """Test that a warning is only emitted when `max_epochs` was not set by the user."""
  
      class CustomModel(BoringModel):
          def training_step(self, *args, **kwargs):
              self.trainer.should_stop = True
  
      match = "`max_epochs` was not set. Setting it to 1000 epochs."
  
      model = CustomModel()
      trainer = Trainer(max_epochs=None, limit_train_batches=1)
      with pytest.warns(PossibleUserWarning, match=match):
          trainer.fit(model)
  
      assert trainer.max_epochs == 1000
      assert trainer.current_epoch == 1
  
      with no_warning_call(
          expected_warning=PossibleUserWarning, match=match
      ):
          Trainer(fast_dev_run=True)
          Trainer(fast_dev_run=1)
  
imports: import pytest
  from lightning.fabric.utilities.warnings import PossibleUserWarning
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning_utilities.test.warning import no_warning_call
label_desc: Use image node_id 2 for calling a global function with example usage: test_max_epochs_not_set_warning() without return types