From 0399076ab0810dc8f711270a48a44c55d697c74b Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 19 Jul 2024 14:54:42 +0200 Subject: [PATCH] test: Only assert warnings we are interested in --- .../test_cloud_resource_context.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/integrations/cloud_resource_context/test_cloud_resource_context.py b/tests/integrations/cloud_resource_context/test_cloud_resource_context.py index 90c78b28ec..49732b00a5 100644 --- a/tests/integrations/cloud_resource_context/test_cloud_resource_context.py +++ b/tests/integrations/cloud_resource_context/test_cloud_resource_context.py @@ -394,13 +394,17 @@ def test_setup_once( else: fake_set_context.assert_not_called() - if warning_called: - correct_warning_found = False + def invalid_value_warning_calls(): + """ + Iterator that yields True if the warning was called with the expected message. + Written as a generator function, rather than a list comprehension, to allow + us to handle exceptions that might be raised during the iteration if the + warning call was not as expected. + """ for call in fake_warning.call_args_list: - if call[0][0].startswith("Invalid value for cloud_provider:"): - correct_warning_found = True - break + try: + yield call[0][0].startswith("Invalid value for cloud_provider:") + except (IndexError, KeyError, TypeError, AttributeError): + ... - assert correct_warning_found - else: - fake_warning.assert_not_called() + assert warning_called == any(invalid_value_warning_calls())