I have a Python AWS Lambda function located in a directory structure like this:
|-lambda
|
|-lambda_function.py
|
|-tests
|
|-test.py
|-mockdata.json
I'm trying to perform unit testing using the unittest module, but I'm having trouble importing the lambda_handler function from the lambda_function.py file inside the test.py file.
I've tried using the following import statement in test.py:
from lambda_function import lambda_handler
However, since test.py is in a subdirectory, I'm getting undefined results and the test is failing.
How can I properly import the lambda_handler function from lambda_function.py when running tests from a subdirectory? Any help would be appreciated. Thanks!
I have tried add parent directory of the test file which is lambda_function.py like below:
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
but it didn't solve the problem.