Skip to content

Commit 5f2aeb9

Browse files
caladdmasonkatz
authored andcommitted
INTERNAL: Fix tests to match new behavior of pytest.raises
1 parent 661425b commit 5f2aeb9

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

test-framework/test-suites/unit/tests/switch/pylib/test_switch_pylib_m7800.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ def test_image_boot_next_error(self, mock_expectmore):
218218
test_switch = SwitchMellanoxM7800(switch_ip_address = 'fakeip', password = 'fakepassword')
219219
error_message = '% strange error'
220220
mock_expectmore.return_value.ask.return_value = [error_message]
221-
with pytest.raises(SwitchException) as exception:
221+
with pytest.raises(SwitchException, match=error_message) as exception:
222222
test_switch.image_boot_next()
223-
assert(error_message in str(exception))
224223

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

269-
with pytest.raises(SwitchException) as exception:
268+
with pytest.raises(SwitchException, match=error_message) as exception:
270269
test_switch.image_delete(image = firmware_name)
271-
assert(error_message in str(exception))
272270

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

302300
error_message = '% unauthorized'
303301
mock_expectmore.return_value.ask.return_value = ['other junk', error_message,]
304-
with pytest.raises(SwitchException) as exception:
302+
with pytest.raises(SwitchException, match=error_message) as exception:
305303
test_switch.image_fetch(url = firmware_url)
306-
assert(error_message in str(exception))
307304

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

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

0 commit comments

Comments
 (0)