import pytest from common.src.aws import client_factories as factories from common.src.enums import AWSRegion CALL_COUNT: int = 3 @pytest.fixture(autouse=True) def patch_session(mocker): return mocker.patch.object(factories, "Session", autospec=True) @pytest.mark.parametrize( "func", [ factories.new_lambda_client, factories.new_secrets_manager_client, factories.new_s3_client, factories.new_sns_client, ], ) def test_new_client_cached(func): func.cache_clear() # Clear the cache before the test try: instances = [func(AWSRegion.US_EAST_1) for _ in range(CALL_COUNT)] assert all( instance is instances[0] for instance in instances ), "All instances should be the same (cached)." finally: # ALWAYS clear the cache after the test to prevent cross-test contamination func.cache_clear()