def test_lambda_callback_with_kwargs(self):
        """Test LambdaCallback's behavior with custom defined callback."""
        batch_size = 4
        model = Sequential(
            [layers.Input(shape=(2,), batch_size=batch_size), layers.Dense(1)]
        )
        model.compile(
            optimizer=optimizers.SGD(), loss=losses.MeanSquaredError()
        )
        x = np.random.randn(16, 2)
        y = np.random.randn(16, 1)
        model.fit(
            x, y, batch_size=batch_size, epochs=1, verbose=0
        )  # Train briefly for evaluation to work.

        def custom_on_test_begin(logs):
            logging.warning("custom_on_test_begin_executed")

        lambda_log_callback = callbacks.LambdaCallback(
            on_test_begin=custom_on_test_begin
        )
        with self.assertLogs(level="WARNING") as logs:
            model.evaluate(
                x,
                y,
                batch_size=batch_size,
                callbacks=[lambda_log_callback],
                verbose=0,
            )
            self.assertTrue(
                any(
                    "custom_on_test_begin_executed" in log
                    for log in logs.output
                )
            )
Test LambdaCallback's behavior with custom defined callback.
keras/src/callbacks/lambda_callback_test.py