diff options
author | John Thacker <johnthacker@gmail.com> | 2022-12-28 00:14:35 -0500 |
---|---|---|
committer | John Thacker <johnthacker@gmail.com> | 2023-01-03 21:08:00 -0500 |
commit | fdc335e68654db8c47f98ab46598d8d4e5a655b9 (patch) | |
tree | fd6abcd5d02fb0ef159b8c746e41481e5eccf848 /test | |
parent | 6581901810a9481f12a616b869e711f568cdf7c0 (diff) |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/subprocesstest.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/test/subprocesstest.py b/test/subprocesstest.py index a3a27d33f6..02422a6cba 100644 --- a/test/subprocesstest.py +++ b/test/subprocesstest.py @@ -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. |