diff --git a/aws_lambda_powertools/utilities/batch/base.py b/aws_lambda_powertools/utilities/batch/base.py index 21b59328ef0..bccaccb4615 100644 --- a/aws_lambda_powertools/utilities/batch/base.py +++ b/aws_lambda_powertools/utilities/batch/base.py @@ -351,6 +351,7 @@ def _prepare(self): """ self.success_messages.clear() self.fail_messages.clear() + self.exceptions.clear() self.batch_response = copy.deepcopy(self.DEFAULT_RESPONSE) def _process_record(self, record: dict) -> Union[SuccessResponse, FailureResponse]: diff --git a/tests/functional/test_utilities_batch.py b/tests/functional/test_utilities_batch.py index 2d9e6bab612..a5e1e706437 100644 --- a/tests/functional/test_utilities_batch.py +++ b/tests/functional/test_utilities_batch.py @@ -895,8 +895,16 @@ def test_batch_processor_error_when_entire_batch_fails(sqs_event_factory, record def lambda_handler(event, context): return processor.response() - # WHEN/THEN + # WHEN calling `lambda_handler` in cold start with pytest.raises(BatchProcessingError) as e: lambda_handler(event, {}) - ret = str(e) - assert ret is not None + + # THEN raise BatchProcessingError + assert "All records failed processing. " in str(e.value) + + # WHEN calling `lambda_handler` in warm start + with pytest.raises(BatchProcessingError) as e: + lambda_handler(event, {}) + + # THEN raise BatchProcessingError + assert "All records failed processing. " in str(e.value)