diff --git a/toolium/test/test_test_cases.py b/toolium/test/test_test_cases.py index c3bad26f..e817b9a5 100644 --- a/toolium/test/test_test_cases.py +++ b/toolium/test/test_test_cases.py @@ -79,3 +79,4 @@ def test_tear_down_fail(logger): # Check logging error messages logger.info.assert_called_once_with('Running new test: %s', 'MockTestClass.mock_fail') logger.error.assert_called_once_with("The test '%s' has failed: %s", 'MockTestClass.mock_fail', 'test error') + pass diff --git a/toolium/test_cases.py b/toolium/test_cases.py index ed87d473..b9782460 100644 --- a/toolium/test_cases.py +++ b/toolium/test_cases.py @@ -63,22 +63,25 @@ def setUp(self): self.logger.info("Running new test: %s", self.get_subclassmethod_name()) def tearDown(self): - # Get unit test exception - if hasattr(self._outcome, 'errors'): - exception_info = self._outcome.errors[-1][1] if len(self._outcome.errors) > 0 else None - else: - exception_info = self._outcome.result.failures[0] if len(self._outcome.result.failures) > 0 else None - exception = exception_info[1] if exception_info else None + # Get error message from unittest errors + error_message = '' + if hasattr(self._outcome, 'errors') and len(self._outcome.errors) > 0: + # Python <3.11 + exception_info = self._outcome.errors[-1][1] + if exception_info: + exception = exception_info[1] + error_message = get_error_message_from_exception(exception) + elif not hasattr(self._outcome, 'errors') and len(self._outcome.result.failures) > 0: + # Python 3.11 + traceback = self._outcome.result.failures[0][1] + error_message = get_error_message_from_traceback(traceback) - if not exception: + # Change test status + if not error_message: self._test_passed = True self.logger.info("The test '%s' has passed", self.get_subclassmethod_name()) else: self._test_passed = False - if hasattr(self._outcome, 'errors'): - error_message = get_error_message_from_exception(exception) - else: - error_message = get_error_message_from_traceback(exception) self.logger.error("The test '%s' has failed: %s", self.get_subclassmethod_name(), error_message) diff --git a/toolium/utils/path_utils.py b/toolium/utils/path_utils.py index 8504d279..a6af05bb 100644 --- a/toolium/utils/path_utils.py +++ b/toolium/utils/path_utils.py @@ -17,10 +17,7 @@ """ from os import makedirs -try: - from os import errno # Py <3.7 -except ImportError: - import errno # Py 3.7+ +import errno import re FILENAME_MAX_LENGTH = 100