def test_interrupt_state_on_keyboard_interrupt(tmp_path, extra_params):
    """Tests that state is set to INTERRUPTED on KeyboardInterrupt."""
    model = BoringModel()

    class InterruptCallback(Callback):
        def on_train_batch_start(self, trainer, pl_module, batch, batch_idx):
            raise KeyboardInterrupt

    trainer = Trainer(callbacks=[InterruptCallback()], default_root_dir=tmp_path, **extra_params)

    with pytest.raises(SystemExit):
        trainer.fit(model)
    assert trainer.interrupted
Tests that state is set to INTERRUPTED on KeyboardInterrupt.
tests/tests_pytorch/trainer/test_states.py