File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -376,3 +376,27 @@ except Exception:
376
376
}
377
377
```
378
378
</details >
379
+
380
+
381
+ ## Testing your code
382
+
383
+ When unit testing your code that makes use of ` inject_lambda_context ` decorator, you need to pass a dummy Lambda Context, or else Logger will fail.
384
+
385
+ This is a Pytest sample that provides the minimum information necessary for Logger to succeed:
386
+
387
+ ``` python:title=fake_lambda_context_for_logger.py
388
+ @pytest.fixture
389
+ def lambda_context ():
390
+ lambda_context = {
391
+ " function_name" : " test" ,
392
+ " memory_limit_in_mb" : 128 ,
393
+ " invoked_function_arn" : " arn:aws:lambda:eu-west-1:809313241:function:test" ,
394
+ " aws_request_id" : " 52fdfc07-2182-154f-163f-5f0f9a621d72" ,
395
+ }
396
+
397
+ return namedtuple(" LambdaContext" , lambda_context.keys())(* lambda_context.values())
398
+
399
+ def test_lambda_handler (lambda_handler , lambda_context ):
400
+ test_event = {' test' : ' event' }
401
+ lambda_handler(test_event, lambda_context) # this will now have a Context object populated
402
+ ```
You can’t perform that action at this time.
0 commit comments