Home > Net >  How do I mock an AWS lambda start_execution in Python?
How do I mock an AWS lambda start_execution in Python?

Time:01-03

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?

CodePudding user response:

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

CodePudding user response:

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()
  • Related