def test_trainer_calls_strategy_on_exception(exception_type, tmp_path):
    """Test that when an exception occurs, the Trainer lets the strategy process it."""
    exception = exception_type("Test exception")

    class ExceptionModel(BoringModel):
        def on_fit_start(self):
            raise exception

    trainer = Trainer(default_root_dir=tmp_path)
    with (
        mock.patch("lightning.pytorch.strategies.strategy.Strategy.on_exception") as on_exception_mock,
        suppress(Exception, SystemExit),
    ):
        trainer.fit(ExceptionModel())
    on_exception_mock.assert_called_once_with(exception)
Test that when an exception occurs, the Trainer lets the strategy process it.
tests/tests_pytorch/trainer/test_trainer.py