-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Setting @mock_aws(config={"lambda": {"use_docker": False}})
on a pytest test causes Lambdas to disappear
#7507
Comments
Hi @andymadge! There are two things at play here:
Your example effectively does the following:
The easiest way to fix this would be to only have a single decorator inside your test case, so it's always obvious which configuration is active at any given point. One way to do this is to have a single fixture:
Note that I've also removed the decorator from the I also added the |
Thanks, that makes sense. I had wondered if it needed configuring earlier, but the only way I could see to configure it differently was by adding the decorator to fixtures, but that didn't seem to do anything. I can see now that I needed to add the config to the original call to So just to check my understanding...
These creation options are covered in https://docs.getmoto.org/en/latest/docs/getting_started.html#moto-usage but I had failed to grasp the fact that this is also the place to configure it. That all seems completely obvious now that I know. Of course you need to configure the object instance when you create it, but my understanding of Moto was lacking and I wasn't piecing together the various ways of instantiating Moto to understand each of them. Thanks for taking the time to explain. |
No problem @andymadge! Glad I could help. I'll close this, but let us know if you have any other questions. |
I'm trying to use Moto and pytest to test a Python script which invokes an AWS Lambda Function.
In my testing,
script_to_test.py
won't complete successfully because it tries to invoke a Lambda Function. I'm using Moto to create a simple dummy Lambda Function that the main script can invoke. As long as that returnsstatus:200
thenscript_to_test.py
should complete successfully, so the"Simple Lambda happy path OK"
response will be ok.(
script_to_test.py
is in fact itself a Lambda Function, but here I'm testing by simply importing it and calling a function from it.)I have Moto working fine for other tests in the suite, but I can't get it to work for this one.
I can create create the dummy Lambda function in a pytest fixture, and I can do
list_functions()
to confirm it exists at the end of the fixture.However, when I then include that fixture in a test, the function is not available in the test.
I'm using:
This is my cut-down test code which illustrates the issue:
I'm running it with
pytest -rP
to see print output.This is the output of the test:
You can see the "Captured stdout setup" shows that
print(boto3.client('lambda').list_functions()['Functions'], "\n")
does list the Lambda function, however the same line in "Captured stdout call" just shows an empty list.If I comment out the line
@mock_aws(config={"lambda": {"use_docker": False},})
then it works and the function is visible in the test, however this doesn't help me since I want to avoid running the lambda in DockerNow we see the
print(boto3.client('lambda').list_functions()['Functions'], "\n")
works correctly in both places.What am I doing wrong here? Or is it a bug?
The text was updated successfully, but these errors were encountered: