Skip to content

Commit

Permalink
INTERNAL: Fix tests to match new behavior of pytest.raises
Browse files Browse the repository at this point in the history
  • Loading branch information
caladd authored and masonkatz committed Sep 11, 2019
1 parent 661425b commit 5f2aeb9
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ def test_image_boot_next_error(self, mock_expectmore):
test_switch = SwitchMellanoxM7800(switch_ip_address = 'fakeip', password = 'fakepassword')
error_message = '% strange error'
mock_expectmore.return_value.ask.return_value = [error_message]
with pytest.raises(SwitchException) as exception:
with pytest.raises(SwitchException, match=error_message) as exception:
test_switch.image_boot_next()
assert(error_message in str(exception))

def test_install_firmware(self, mock_expectmore, test_file):
"""Expect this to try to install the user requested firmware."""
Expand Down Expand Up @@ -266,9 +265,8 @@ def test_image_delete_error(self, mock_expectmore):
error_message = '% file not found'
mock_expectmore.return_value.ask.return_value = [error_message]

with pytest.raises(SwitchException) as exception:
with pytest.raises(SwitchException, match=error_message) as exception:
test_switch.image_delete(image = firmware_name)
assert(error_message in str(exception))

@pytest.mark.parametrize('protocol', SwitchMellanoxM7800.SUPPORTED_IMAGE_FETCH_PROTOCOLS)
def test_image_fetch(self, mock_expectmore, protocol):
Expand Down Expand Up @@ -301,9 +299,8 @@ def test_image_fetch_error_with_message(self, mock_expectmore):

error_message = '% unauthorized'
mock_expectmore.return_value.ask.return_value = ['other junk', error_message,]
with pytest.raises(SwitchException) as exception:
with pytest.raises(SwitchException, match=error_message) as exception:
test_switch.image_fetch(url = firmware_url)
assert(error_message in str(exception))

def test_image_fetch_error_without_message(self, mock_expectmore):
"""Expect an error to be raised due to a missing success indicator.
Expand All @@ -317,7 +314,7 @@ def test_image_fetch_error_without_message(self, mock_expectmore):
mock_expectmore.return_value.ask.return_value = irrelevant_output
with pytest.raises(SwitchException) as exception:
test_switch.image_fetch(url = firmware_url)
assert(not any((output in str(exception) for output in irrelevant_output)))
assert not any((output in str(exception.value) for output in irrelevant_output))

@pytest.mark.parametrize('input_file', FIRMWARE_INPUT_DATA)
def test_show_images(self, mock_expectmore, input_file, test_file):
Expand Down

0 comments on commit 5f2aeb9

Please sign in to comment.