Description
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
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript