diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index ffde4d39b..4ddfa0563 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -34,6 +34,12 @@ from tests.app.db import ( ) +def setup_function(_function): + # pytest will run this function before each test. It makes sure the + # state of the cache is not shared between tests. + send_to_providers.provider_cache.clear() + + def test_provider_to_use_should_return_random_provider(mocker, notify_db_session): mmg = get_provider_details_by_identifier('mmg') firetext = get_provider_details_by_identifier('firetext') @@ -53,8 +59,6 @@ def test_provider_to_use_should_cache_repeated_calls(mocker, notify_db_session): wraps=send_to_providers.random.choices, ) - send_to_providers.provider_cache.clear() - results = [ send_to_providers.provider_to_use('sms', international=False) for _ in range(10) @@ -90,8 +94,6 @@ def test_provider_to_use_raises_if_no_active_providers(mocker, restore_provider_ mmg = get_provider_details_by_identifier('mmg') mmg.active = False - send_to_providers.provider_cache.clear() - with pytest.raises(Exception): send_to_providers.provider_to_use('sms', international=True) @@ -643,7 +645,6 @@ def test_should_send_sms_to_international_providers( international=True, reply_to_text=sample_template.service.get_default_sms_sender() ) - send_to_providers.provider_cache.clear() send_to_providers.send_sms_to_provider( notification_uk ) @@ -694,7 +695,6 @@ def test_should_handle_sms_sender_and_prefix_message( template = create_template(service, content='bar') notification = create_notification(template, reply_to_text=sms_sender) - send_to_providers.provider_cache.clear() send_to_providers.send_sms_to_provider(notification) mmg_client.send_sms.assert_called_once_with(