From 2d266fbc87c6e1f2bd7bb887e254938278b8d2cc Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Fri, 9 Aug 2019 14:58:46 -0400 Subject: [PATCH] Fix unit tests to work with pytest >= 5.0 (#60246) pytest made a change in the way the message from ExceptionInfo objects was returned. https://docs.pytest.org/en/latest/changelog.html#pytest-5-0-0-2019-06-28 --- test/units/executor/module_common/test_recursive_finder.py | 4 ++-- .../module_utils/common/validation/test_check_type_int.py | 2 +- test/units/modules/network/ftd/test_ftd_file_download.py | 2 +- test/units/modules/network/ftd/test_ftd_file_upload.py | 2 +- test/units/plugins/terminal/test_junos.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/units/executor/module_common/test_recursive_finder.py b/test/units/executor/module_common/test_recursive_finder.py index f2dc5e3183a..0866623b7e4 100644 --- a/test/units/executor/module_common/test_recursive_finder.py +++ b/test/units/executor/module_common/test_recursive_finder.py @@ -117,14 +117,14 @@ class TestRecursiveFinder(object): data = b'#!/usr/bin/python\ndef something(:\n pass\n' with pytest.raises(ansible.errors.AnsibleError) as exec_info: recursive_finder(name, data, *finder_containers) - assert 'Unable to import fake_module due to invalid syntax' in str(exec_info) + assert 'Unable to import fake_module due to invalid syntax' in str(exec_info.value) def test_module_utils_with_identation_error(self, finder_containers): name = 'fake_module' data = b'#!/usr/bin/python\n def something():\n pass\n' with pytest.raises(ansible.errors.AnsibleError) as exec_info: recursive_finder(name, data, *finder_containers) - assert 'Unable to import fake_module due to unexpected indent' in str(exec_info) + assert 'Unable to import fake_module due to unexpected indent' in str(exec_info.value) def test_from_import_toplevel_package(self, finder_containers, mocker): if PY2: diff --git a/test/units/module_utils/common/validation/test_check_type_int.py b/test/units/module_utils/common/validation/test_check_type_int.py index f07466dd184..22cedf61481 100644 --- a/test/units/module_utils/common/validation/test_check_type_int.py +++ b/test/units/module_utils/common/validation/test_check_type_int.py @@ -31,4 +31,4 @@ def test_check_type_int_fail(): for case in test_cases: with pytest.raises(TypeError) as e: check_type_int(case) - assert 'cannot be converted to an int' in to_native(e) + assert 'cannot be converted to an int' in to_native(e.value) diff --git a/test/units/modules/network/ftd/test_ftd_file_download.py b/test/units/modules/network/ftd/test_ftd_file_download.py index f11085e43de..ebb465e9eb5 100644 --- a/test/units/modules/network/ftd/test_ftd_file_download.py +++ b/test/units/modules/network/ftd/test_ftd_file_download.py @@ -48,7 +48,7 @@ class TestFtdFileDownload(object): with pytest.raises(AnsibleFailJson) as ex: self.module.main() - assert 'missing required arguments: %s' % missing_arg in str(ex) + assert 'missing required arguments: %s' % missing_arg in str(ex.value) def test_module_should_fail_when_no_operation_spec_found(self, connection_mock): connection_mock.get_operation_spec.return_value = None diff --git a/test/units/modules/network/ftd/test_ftd_file_upload.py b/test/units/modules/network/ftd/test_ftd_file_upload.py index bcb1ed994c3..addb0126018 100644 --- a/test/units/modules/network/ftd/test_ftd_file_upload.py +++ b/test/units/modules/network/ftd/test_ftd_file_upload.py @@ -30,7 +30,7 @@ class TestFtdFileUpload(object): with pytest.raises(AnsibleFailJson) as ex: self.module.main() - assert 'missing required arguments: %s' % missing_arg in str(ex) + assert 'missing required arguments: %s' % missing_arg in str(ex.value) def test_module_should_fail_when_no_operation_spec_found(self, connection_mock): connection_mock.get_operation_spec.return_value = None diff --git a/test/units/plugins/terminal/test_junos.py b/test/units/plugins/terminal/test_junos.py index d5ba4709e50..b863bb7b03a 100644 --- a/test/units/plugins/terminal/test_junos.py +++ b/test/units/plugins/terminal/test_junos.py @@ -52,4 +52,4 @@ def test_on_open_shell_raises_problem_setting_terminal_config(junos_terminal): with pytest.raises(AnsibleConnectionFailure) as exc: junos_terminal.on_open_shell() - assert 'unable to set terminal parameters' in str(exc) + assert 'unable to set terminal parameters' in str(exc.value)