code: def test_trainer_flag(caplog):
      class TestModel(BoringModel):
          def on_fit_start(self):
              raise SystemExit()
  
      trainer = Trainer(max_time={"seconds": 1337})
      with pytest.raises(SystemExit):
          trainer.fit(TestModel())
      timer = [c for c in trainer.callbacks if isinstance(c, Timer)][0]
      assert timer._duration == 1337
  
      trainer = Trainer(max_time={"seconds": 1337}, callbacks=[Timer()])
      with pytest.raises(SystemExit), caplog.at_level(
          level=logging.INFO
      ):
          trainer.fit(TestModel())
      assert "callbacks list already contains a Timer" in caplog.text
  
      # Make sure max_time still honored even if max_epochs == -1
      trainer = Trainer(max_time={"seconds": 1}, max_epochs=-1)
      with pytest.raises(SystemExit):
          trainer.fit(TestModel())
      timer = [c for c in trainer.callbacks if isinstance(c, Timer)][0]
      assert timer._duration == 1
      assert trainer.max_epochs == -1
      assert trainer.max_steps == -1
  
imports: import logging
  import time
  from datetime import timedelta
  from unittest.mock import Mock, patch
  import pytest
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.callbacks.timer import Timer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 1 for calling a global function with example usage: test_trainer_flag(caplog) without return types