From 5f2aeb91ec2e8cd3d664b27ed3e08c01d7234cb9 Mon Sep 17 00:00:00 2001 From: Chris Ladd Date: Wed, 11 Sep 2019 09:15:56 -0700 Subject: [PATCH] INTERNAL: Fix tests to match new behavior of `pytest.raises` --- .../tests/switch/pylib/test_switch_pylib_m7800.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test-framework/test-suites/unit/tests/switch/pylib/test_switch_pylib_m7800.py b/test-framework/test-suites/unit/tests/switch/pylib/test_switch_pylib_m7800.py index 2f4aee1eb..88dc2558c 100644 --- a/test-framework/test-suites/unit/tests/switch/pylib/test_switch_pylib_m7800.py +++ b/test-framework/test-suites/unit/tests/switch/pylib/test_switch_pylib_m7800.py @@ -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.""" @@ -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): @@ -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. @@ -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):