@@ -391,6 +391,30 @@ def handler(event, context):
391
391
assert len (log ) == 0
392
392
393
393
394
+ def test_flush_buffer_log_output_without_buffer_config (stdout , service_name , lambda_context , monkeypatch ):
395
+ # Set initial trace ID for first Lambda invocation
396
+ monkeypatch .setenv (constants .XRAY_TRACE_ID_ENV , "1-67c39786-5908a82a246fb67f3089263f" )
397
+
398
+ # GIVEN A logger without buffer configuration
399
+ logger = Logger (level = "DEBUG" , service = service_name , stream = stdout )
400
+
401
+ @logger .inject_lambda_context (flush_buffer_on_uncaught_error = True )
402
+ def handler (event , context ):
403
+ # Log messages are not buffered and should be output immediately
404
+ logger .debug ("debug message - 1" )
405
+ logger .debug ("debug message - 2" )
406
+ raise ValueError ("Test error" )
407
+
408
+ # WHEN Invoking the handler and expecting a ValueError
409
+ # AND flush_buffer_on_uncaught_error is True but there is no logger buffer configuration
410
+ with pytest .raises (ValueError ):
411
+ handler ({}, lambda_context )
412
+
413
+ # THEN Verify that log messages are flushed without any exception
414
+ log = capture_multiple_logging_statements_output (stdout )
415
+ assert len (log ) == 2 , "Expected two log messages"
416
+
417
+
394
418
def test_buffer_configuration_and_buffer_propagation_across_logger_instances (stdout , service_name , monkeypatch ):
395
419
monkeypatch .setenv (constants .XRAY_TRACE_ID_ENV , "1-67c39786-5908a82a246fb67f3089263f" )
396
420
0 commit comments