From 83f40b85f4c81b5120d1985bbb972000a5de8e7a Mon Sep 17 00:00:00 2001 From: sahasweety Date: Fri, 17 Jul 2026 11:52:20 +0530 Subject: [PATCH] fix: remove patch logger in test, use caplog instead (Closes #37468) (#39159) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../services/test_webhook_service.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/api/tests/unit_tests/services/test_webhook_service.py b/api/tests/unit_tests/services/test_webhook_service.py index 4babcd049c8..2e6bc70bca0 100644 --- a/api/tests/unit_tests/services/test_webhook_service.py +++ b/api/tests/unit_tests/services/test_webhook_service.py @@ -13,7 +13,9 @@ from services.trigger.webhook_service import WebhookService class TestWebhookServiceUnit: """Unit tests for WebhookService focusing on business logic without database dependencies.""" - def test_trigger_workflow_execution_propagates_quota_error_without_error_log(self): + def test_trigger_workflow_execution_propagates_quota_error_without_error_log( + self, caplog: pytest.LogCaptureFixture + ): webhook_trigger = MagicMock( webhook_id="webhook-123", tenant_id="tenant-123", @@ -24,6 +26,7 @@ class TestWebhookServiceUnit: quota_charge = MagicMock() quota_error = QuotaExceededError(feature="workflow", tenant_id="tenant-123", required=1) + caplog.set_level(logging.INFO) with ( patch( "services.trigger.webhook_service.EndUserService.get_or_create_end_user_by_type", @@ -36,8 +39,6 @@ class TestWebhookServiceUnit: "services.trigger.webhook_service.AsyncWorkflowService.trigger_workflow_async", side_effect=quota_error, ), - patch("services.trigger.webhook_service.logger.info") as mock_log_info, - patch("services.trigger.webhook_service.logger.exception") as mock_log_exception, ): with pytest.raises(QuotaExceededError) as exc_info: WebhookService.trigger_workflow_execution( @@ -48,13 +49,13 @@ class TestWebhookServiceUnit: assert exc_info.value is quota_error quota_charge.refund.assert_called_once_with() - mock_log_info.assert_called_once_with( - "Tenant %s quota exceeded for feature %s, skipping webhook trigger %s", - webhook_trigger.tenant_id, - quota_error.feature, - webhook_trigger.webhook_id, + + # Verify logs using caplog instead of mock_log + assert len(caplog.records) == 1 + assert caplog.records[0].levelno == logging.INFO + assert caplog.records[0].message == ( + "Tenant tenant-123 quota exceeded for feature workflow, skipping webhook trigger webhook-123" ) - mock_log_exception.assert_not_called() def test_extract_webhook_data_json(self): """Test webhook data extraction from JSON request."""