def test_validate_unique_callback_state_key():
    """Test that we raise an error if the state keys collide, leading to missing state in the checkpoint."""

    class MockCallback(Callback):
        @property
        def state_key(self):
            return "same_key"

        def state_dict(self):
            # pretend these callbacks are stateful by overriding the `state_dict` hook
            return {"state": 1}

    with pytest.raises(RuntimeError, match="Found more than one stateful callback of type `MockCallback`"):
        Trainer(callbacks=[MockCallback(), MockCallback()])
Test that we raise an error if the state keys collide, leading to missing state in the checkpoint.
tests/tests_pytorch/trainer/connectors/test_callback_connector.py