Skip to content

Feature: Test Framework Utilities #193

Closed
@beanaroo

Description

@beanaroo

Describe the solution you'd like
This is a follow up of #144 (comment).

Having Data Classes and Typing has made a significant difference! Being able to leverage them in testing using provided samples, mocks and/or fixtures could be useful too.

A dedicated module might make sense in order not to modify existing utilities to accommodate testing ability.

Describe alternatives you've considered

  • aws_lambda_context module as described in the linked thread.
  • Sub-classing LambdaContext with setters only - not possible as Python requires @property to be redeclared

Additional context

In the mean time, I've had success with:

import pytest
from aws_lambda_powertools.utilities.typing import LambdaContext


class MockLambdaContext(LambdaContext):

    def __init__(self):
        self._function_name = 'test-fn'
        self._memory_limit_in_mb = 128
        self._invoked_function_arn = 'arn:aws:lambda:us-east-1:12345678:function:test-fn'
        self._aws_request_id = '52fdfc07-2182-154f-163f-5f0f9a621d72'


@pytest.fixture
def lambda_context() -> LambdaContext:
    return MockLambdaContext()

I was also not able to use the documented suggestion as provided. Not sure if this warrants a separate issue.

Screenshot

image

Metadata

Metadata

Assignees

Labels

feature-requestfeature requestneed-customer-feedbackRequires more customers feedback before making or revisiting a decision

Type

No type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions