Search code examples
pythonamazon-web-serviceslambdapytest

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?


Solution

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