Skip to content

Commit 8e5673a

Browse files
committed
chore: add test to reproduce clear state bug with custom keys
1 parent f24332d commit 8e5673a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/functional/test_logger.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,29 @@ def handler(event, context):
683683
assert key in second_log
684684

685685

686+
def test_clear_state_keeps_custom_keys(lambda_context, stdout, service_name):
687+
# GIVEN
688+
date_format = "%Y"
689+
location_format = "%(module)s:%(funcName)s:%(lineno)d"
690+
logger = Logger(service=service_name, stream=stdout, location=location_format, datefmt=date_format)
691+
692+
# WHEN clear_state is set
693+
@logger.inject_lambda_context(clear_state=True)
694+
def handler(event, context):
695+
logger.info("Foo")
696+
697+
# THEN all standard keys should be available as usual
698+
handler({}, lambda_context)
699+
handler({}, lambda_context)
700+
701+
first_log, second_log = capture_multiple_logging_statements_output(stdout)
702+
703+
assert re.fullmatch("[0-9]{4}", first_log["timestamp"])
704+
assert re.fullmatch("[0-9]{4}", second_log["timestamp"])
705+
assert re.fullmatch(".+:.+:[0-9]+", first_log["location"])
706+
assert re.fullmatch(".+:.+:[0-9]+", second_log["location"])
707+
708+
686709
def test_clear_state_keeps_exception_keys(lambda_context, stdout, service_name):
687710
# GIVEN
688711
logger = Logger(service=service_name, stream=stdout)

0 commit comments

Comments
 (0)