how to mock an outside init of aws lambda function that execute on the beginning of the module?

24 views Asked by At

Consider I have the following import in a pytest file:

from xyz import lambda_handler

But in xyz.py

We have:

def foo_init():
    return 1. 

x = foo_init()
def lambda_handler():
   # doing some logic and using x above

now in my pytest file:

I want to test function lambda_handler, so I need to import it, as a result of importing I get x = foo_init() executed.
So I want to mock the foo_init() part which is executed with the import when I do the import the lambda_handler in my pytest file.

Please note that it is common to have outside of the lambda_handler one time initializations outside of the lambda_handler scope which is called multiple times each time lambda is triggered.

Thanks

0

There are 0 answers