Skip to content

Commit

Permalink
test: Only assert warnings we are interested in
Browse files Browse the repository at this point in the history
  • Loading branch information
szokeasaurusrex committed Jul 22, 2024
1 parent 93a3242 commit 0399076
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 0399076

Please sign in to comment.