Amit
Amit

Reputation: 266

How to write unit test for aws lambda handler function (Python)

Everyone

I have a function which is the handler for aws lambdafunction.

def data_list(event, data_subject):
    dynamodb = boto3.resource("dynamodb")
    table = dynamodb.Table("TestTable")
    print("DATA_LIST")

    def get_col_name(data_subject):
        if data_subject == "X":
            return 'something'
        elif data_subject == "y":
            return 'some other things'
        elif data_subject == "c":
            return 'really'

    def another_function(var):
        pass

I have multiple function under data_list function how can we write unittest cases for each individual function which is under data_list function

Upvotes: 0

Views: 1431

Answers (1)

Alan
Alan

Reputation: 3417

Don't.

Instead move them out from the lambda handler function so that you can test them entirely separately.

Then make the lambda handler function it's self so small and simple that you barely need to test it, and can handle testing it with system tests.

Upvotes: 3

Related Questions