Replies: 2 comments 1 reply
-
Hi @ashemedai, can you share a snippet of what you are trying to test? BTW, we don't use |
Beta Was this translation helpful? Give feedback.
-
Ola Leandro, I have a Lambda that I want to output some structured logging towards CloudWatch for others to easily do operational monitoring/troubleshooting from. As such I want to ensure the structured logging does the right thing. So something like this in my Lambda: def process_body(data):
# code to get the right data from events and put in a dict called data_keys
log.info("Triggered X", data=data_keys) And then with pytest I wanted to use caplog to get the structured logging data and assert on that. E.g. a log like this: {"level":"INFO","location":"process_body:93","message":"Triggered X","timestamp":"2024-08-22 11:51:29,865+0200","service":"lambdafunc","data":{...}} But using caplog, I can only get something like this, since the structured log is output to stdout and not the logging that pytest can access:
So I figured that capsys would be helpful here, but nope, using After posting my question, I look at the logger tests if you folks did something like this. So I will give it a try. |
Beta Was this translation helpful? Give feedback.
-
So I am currently using pytest for building my unit tests. And while I can use
caplog
withPOWERTOOLS_LOG_DEDUPLICATION_DISABLED
to test the text of simple log.info() calls, I am currently breaking my head to get the structured log output that's printed to stdout. Using capsys and such does not seem to work as I only get empty strings. I am probably missing something super obvious, so any help will be useful to get me unstuck.Beta Was this translation helpful? Give feedback.
All reactions