Skip to content

Commit fd19e73

Browse files
committed
improv: add testing section to Logger #161
Signed-off-by: heitorlessa <[email protected]>
1 parent 4090c8c commit fd19e73

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/content/core/logger.mdx

+24
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,27 @@ except Exception:
376376
}
377377
```
378378
</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+
```

0 commit comments

Comments
 (0)