tests: Get tests working with Python 3.11 (except with pytest)

We use a common idiom ( https://stackoverflow.com/a/39606065
https://gist.github.com/hynekcer/1b0a260ef72dae05fe9611904d7b9675 )
for getting the results of our unittest.TestCases in the tearDown
method. This method accesses a private property, and that private
property was removed in Python 3.11

The StackOverflow answer has been updated with a new approach for
Python 3.11, which also uses a private property. This fixes things
for CTest (and the test target when building), but it still doesn't
work when using pytest's unittest support.

Ping #18740
This commit is contained in:
John Thacker 2022-12-28 00:14:35 -05:00
parent 6581901810
commit fdc335e686
1 changed files with 8 additions and 1 deletions

View File

@ -165,7 +165,14 @@ class SubprocessTestCase(unittest.TestCase):
# It remains None when running in debug mode (`pytest --pdb`).
# The property is available since Python 3.4 until at least Python 3.7.
if self._outcome:
for test_case, exc_info in self._outcome.errors:
if hasattr(self._outcome, 'errors'):
# Python 3.4 - 3.10
result = self.defaultTestResult()
self._feedErrorsToResult(result, self._outcome.errors)
else:
# Python 3.11+
result = self._outcome.result
for test_case, exc_info in (result.errors + result.failures):
if exc_info:
return True
# No errors occurred or running in debug mode.