diff --git a/src/silx/gui/utils/testutils.py b/src/silx/gui/utils/testutils.py index 31dd5edae7..237487d1c3 100644 --- a/src/silx/gui/utils/testutils.py +++ b/src/silx/gui/utils/testutils.py @@ -1,6 +1,6 @@ # /*########################################################################## # -# Copyright (c) 2016-2022 European Synchrotron Radiation Facility +# Copyright (c) 2016-2023 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,7 @@ __authors__ = ["T. Vincent"] __license__ = "MIT" -__date__ = "22/07/2022" +__date__ = "22/11/2023" import gc @@ -138,23 +138,26 @@ def setUp(self): self.__class__._exceptions = [] def _currentTestSucceeded(self): - if hasattr(self, '_outcome'): - if hasattr(self, '_feedErrorsToResult'): - # For Python 3.4 -3.10 - result = self.defaultTestResult() # these 2 methods have no side effects - if hasattr(self._outcome, 'errors'): - self._feedErrorsToResult(result, self._outcome.errors) - else: - # Python 3.11+ - result = self._outcome.result + if hasattr(self._outcome, 'errors'): + # Python 3.4 - 3.10 (These two methods have no side effects) + result = self.defaultTestResult() + self._feedErrorsToResult(result, self._outcome.errors) else: - # For Python < 3.4 - result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups) - - skipped = self.id() in [case.id() for case, _ in result.skipped] - error = self.id() in [case.id() for case, _ in result.errors] - failure = self.id() in [case.id() for case, _ in result.failures] - return not error and not failure and not skipped + # Python 3.11+ + result = self._outcome.result + ok = all(test != self for test, text in result.errors + result.failures) + + # Demo output: (print short info immediately - not important) + if ok: + print('\nOK: %s' % (self.id(),)) + for typ, errors in (('ERROR', result.errors), ('FAIL', result.failures)): + for test, text in errors: + if test is self: + # the full traceback is in the variable `text` + msg = [x for x in text.split('\n')[1:] + if not x.startswith(' ')][0] + print("\n\n%s: %s\n %s" % (typ, self.id(), msg)) + return ok def _checkForUnreleasedWidgets(self): """Test fixture checking that no more widgets exists."""