Skip to content

Commit

Permalink
Compatibility with pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
vasole committed Nov 22, 2023
1 parent c20b4d2 commit 07e3f8d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/silx/gui/utils/testutils.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,7 +25,7 @@

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "22/07/2022"
__date__ = "22/11/2023"


import gc
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 07e3f8d

Please sign in to comment.