Skip to content

Commit 0399076

Browse files
test: Only assert warnings we are interested in
1 parent 93a3242 commit 0399076

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/integrations/cloud_resource_context/test_cloud_resource_context.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,17 @@ def test_setup_once(
394394
else:
395395
fake_set_context.assert_not_called()
396396

397-
if warning_called:
398-
correct_warning_found = False
397+
def invalid_value_warning_calls():
398+
"""
399+
Iterator that yields True if the warning was called with the expected message.
400+
Written as a generator function, rather than a list comprehension, to allow
401+
us to handle exceptions that might be raised during the iteration if the
402+
warning call was not as expected.
403+
"""
399404
for call in fake_warning.call_args_list:
400-
if call[0][0].startswith("Invalid value for cloud_provider:"):
401-
correct_warning_found = True
402-
break
405+
try:
406+
yield call[0][0].startswith("Invalid value for cloud_provider:")
407+
except (IndexError, KeyError, TypeError, AttributeError):
408+
...
403409

404-
assert correct_warning_found
405-
else:
406-
fake_warning.assert_not_called()
410+
assert warning_called == any(invalid_value_warning_calls())

0 commit comments

Comments
 (0)