diff --git a/tests/app/test_template_previews.py b/tests/app/test_template_previews.py index 37554be34..1954c3c9d 100644 --- a/tests/app/test_template_previews.py +++ b/tests/app/test_template_previews.py @@ -5,6 +5,7 @@ from unittest.mock import Mock import pytest from notifications_utils.template import LetterPreviewTemplate +from app import load_service_before_request from app.template_previews import ( TemplatePreview, get_page_count_for_letter, @@ -58,6 +59,10 @@ def test_from_database_object_makes_request( expected_filename, mock_get_service_letter_template ): + # This test is calling `current_service` outside a Flask endpoint, so we need to make sure + # `service` is in the `_request_ctx_stack` to avoid an error + load_service_before_request() + resp = Mock(content='a', status_code='b', headers={'c': 'd'}) request_mock = mocker.patch('app.template_previews.requests.post', return_value=resp) mocker.patch('app.template_previews.current_service', letter_branding=letter_branding)