Skip to content

Instantly share code, notes, and snippets.

@peacing
Last active August 19, 2020 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peacing/0c93004f82a1cf136dadd4f8637a2beb to your computer and use it in GitHub Desktop.
Save peacing/0c93004f82a1cf136dadd4f8637a2beb to your computer and use it in GitHub Desktop.
import boto3
import pytest
from lambda_function import *
class MockBotoSession:
class Session:
def client(self, service_name, region_name):
# create a flexible Client class for any boto3 client
class Client:
def list_crawlers(self):
# hardcode the list_crawlers response
return {'CrawlerNames': ['crawler_1', 'crawler_2',]}
return Client()
def test_lambda_handler(monkeypatch):
# patch boto session with a mock client
monkeypatch.setattr(boto3, 'session', MockBotoSession)
response = lambda_handler(event=test_event, context={})
assert response == 'something'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment