Patchwork D11690: python: compatibility for python 3.11 (issue6604)

login
register
mail settings
Submitter phabricator
Date Oct. 19, 2021, 2:09 p.m.
Message ID <differential-rev-PHID-DREV-lyoek2jacdkfh7dnag5k-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50014/
State Superseded
Headers show

Comments

phabricator - Oct. 19, 2021, 2:09 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The `unittest._TextTestResult` alias has been removed.
  The "new" name has been available since 3.2, and we only support 3.5.3+.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D11690

AFFECTED FILES
  tests/basic_test_result.py
  tests/run-tests.py

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -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)
 
diff --git a/tests/basic_test_result.py b/tests/basic_test_result.py
--- a/tests/basic_test_result.py
+++ b/tests/basic_test_result.py
@@ -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