Skip to content

Feature request: support clearing/scoped caches for testing #1092

Closed
@huonw

Description

@huonw

Use case

We're testing our code with mocked AWS services using moto (rather than replacing/patching the calls entirely), and it works well. However, powertools provides various caches that are great for production, but cause unintended linkage/interference between tests. We're hitting this particularly in aws_lambda_powertools.utilities.parameters.get_secret, but it applies to other parts of that module, and likely any other global caches built into this package.

It'd be nice to be able to run tests isolated without having to manually write force_fetch=running_in_tests() or similar everywhere.

Solution/User Experience

Some method for clearing caches. For instance, a global aws_powertools_lambda.clear_caches() or aws_powertools_lambda.utilities.parameters.clear_caches(). Tests could then have set-up that calls that to ensure each one has a fresh environment.

Alternative solutions

Alternatives:

  • an environment variable that disables caching entirely, which can be set during tests runs (not so good because the deployed behaviour differs)
  • using contextvars to have the "global" caches actually be scope-able (this seems complicated)

Acknowledgment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions