简体   繁体   中英

How do I mock an AWS lambda start_execution in Python?

I am testing a function whose very last line of code starts the execution of an AWS lambda. This part is not relevant to my test, so I want to mock the call to client.start_execution() so that instead of actually triggering AWS it returns None.

Is there a way to use pytest mocks to simply replace the response of this function with a generic None?

A quick solution, if you do not need any specific logic, it to simply replace this function by a custom function. For example:

from aws_stuff import client

def return_none():
    return None

client.start_execution = return_none

Assuming that the actual call you want to mock is from the Step Functions service, then you can utilize the moto library:

http://docs.getmoto.org/en/latest/docs/services/stepfunctions.html

@mock_stepfunctions
def test_stepfunctions_behaviour:
    your_function_call()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM