python: compatibility for python 3.11 (issue6604) stable
authorRaphaël Gomès <rgomes@octobus.net>
Tue, 19 Oct 2021 16:05:20 +0200
branchstable
changeset 47898 3a95a4e660b9
parent 47897 f6b045910d82
child 47899 1ea289e34c70
python: compatibility for python 3.11 (issue6604) The `unittest._TextTestResult` alias has been removed. The "new" name has been available since 3.2, and we only support 3.5.3+. Differential Revision: https://phab.mercurial-scm.org/D11690
tests/basic_test_result.py
tests/run-tests.py
--- a/tests/basic_test_result.py	Wed Oct 20 16:54:43 2021 +0200
+++ b/tests/basic_test_result.py	Tue Oct 19 16:05:20 2021 +0200
@@ -1,9 +1,15 @@
 from __future__ import absolute_import, print_function
 
+import sys
 import unittest
 
+if sys.version_info[0] < 3:
+    base_class = unittest._TextTestResult
+else:
+    base_class = unittest.TextTestResult
 
-class TestResult(unittest._TextTestResult):
+
+class TestResult(base_class):
     def __init__(self, options, *args, **kwargs):
         super(TestResult, self).__init__(*args, **kwargs)
         self._options = options
--- a/tests/run-tests.py	Wed Oct 20 16:54:43 2021 +0200
+++ b/tests/run-tests.py	Tue Oct 19 16:05:20 2021 +0200
@@ -2233,12 +2233,15 @@
 firstlock = threading.RLock()
 firsterror = False
 
-
-class TestResult(unittest._TextTestResult):
+if PYTHON3:
+    base_class = unittest.TextTestResult
+else:
+    base_class = unittest._TextTestResult
+
+
+class TestResult(base_class):
     """Holds results when executing via unittest."""
 
-    # Don't worry too much about accessing the non-public _TextTestResult.
-    # It is relatively common in Python testing tools.
     def __init__(self, options, *args, **kwargs):
         super(TestResult, self).__init__(*args, **kwargs)