Skip to content

Provide a LambdaContext object for use in testing #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexmuller opened this issue Nov 18, 2021 · 3 comments
Closed

Provide a LambdaContext object for use in testing #833

alexmuller opened this issue Nov 18, 2021 · 3 comments
Labels
feature-request feature request

Comments

@alexmuller
Copy link

Is your feature request related to a problem? Please describe.

We test our Lambdas with pytest and do something like this:

event = {}
context = {}
response = handler(event, context)
assert response == 1

When integrating this project we discovered that we'd have to set up a LambdaContext object and pass that in.

Describe the solution you'd like

It would be great if this library provided a context-like object that we could use in our tests

from aws_lambda_powertools.utilities.typing.lambda_context import LambdaContext
context = LambdaContext(function_name='test', ...)

response = handler(event, context)

However the LambdaContext object (which is provided for IDE type hints) doesn't allow properties to be set.

Describe alternatives you've considered

We've used this snippet of code:

lambda_context = {
    'function_name': 'test',
    ...
}
context = namedtuple("LambdaContext", lambda_context.keys())(*lambda_context.values())

from here but it would be lovely to have this built-in to the library.

@alexmuller alexmuller added feature-request feature request triage Pending triage from maintainers labels Nov 18, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Nov 18, 2021

Thanks for opening your first issue here! We'll come back to you as soon as we can.

@heitorlessa
Copy link
Contributor

hey @alexmuller - Check this out: #1169

We would love ideas on what a testing utility could look like. Lambda Context would be a quick one, but interested to hear your thoughts on how other events could look like, and what else could be helpful (and their UX more or less).

@alexmuller
Copy link
Author

Thank you @heitorlessa, this looks great! The Lambda context would be a brilliant first step for me - but I'm also going to have a think about event handlers for SQS and SNS which would also be useful.

I'm going to close this issue as it's on the roadmap - thanks very much for your reply.

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request
Projects
None yet
Development

No branches or pull requests

2 participants