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