def test_has_already_handler(handler, expected_return):
    """Test that the SignalConnector detects whether a signal handler is already attached."""
    with mock.patch("lightning.pytorch.trainer.connectors.signal_connector.signal.getsignal", return_value=handler):
        assert _SignalConnector._has_already_handler(signal.SIGTERM) is expected_return
Test that the SignalConnector detects whether a signal handler is already attached.
tests/tests_pytorch/trainer/connectors/test_signal_connector.py