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

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

    datamodule = BoringDataModule()
    datamodule.on_exception = Mock()
    trainer = Trainer(default_root_dir=tmp_path)

    with suppress(Exception, SystemExit):
        trainer.fit(ExceptionModel(), datamodule=datamodule)
    datamodule.on_exception.assert_called_once_with(exception)
Test that when an exception occurs, the Trainer lets the data module process it.
tests/tests_pytorch/trainer/test_trainer.py