fix test failed due to python3.10

This commit is contained in:
caodongxia 2022-04-02 11:14:55 +08:00
parent 68215a8a3f
commit ddeb2bd42c
3 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,37 @@
From 840f9230f9fc4433237517310b5b3958b7382f09 Mon Sep 17 00:00:00 2001
From: caodongxia <315816521@qq.com>
Date: Sat, 2 Apr 2022 11:00:19 +0800
Subject: [PATCH] fix for python3.10
Refer: https://github.com/testing-cabal/testtools/commit/254998e2e88835eaa634d9729dddcc3d4b5bc32f
Refer: https://github.com/testing-cabal/testtools/commit/1d698cf91cb2205aedc018e465a2e17c5a6a3e94
---
testtools/tests/test_testresult.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/testtools/tests/test_testresult.py b/testtools/tests/test_testresult.py
index d863794..e06ea03 100644
--- a/testtools/tests/test_testresult.py
+++ b/testtools/tests/test_testresult.py
@@ -2681,6 +2681,8 @@ class TestNonAsciiResults(TestCase):
"""Syntax errors should still have fancy special-case formatting"""
if platform.python_implementation() == "PyPy":
spaces = ' '
+ elif sys.version_info >= (3, 10):
+ spaces = ' '
else:
spaces = ' '
textoutput = self._test_external_case("exec ('f(a, b c)')")
@@ -2755,6 +2757,9 @@ class TestNonAsciiResults(TestCase):
textoutput = self._setup_external_case("import bad")
self._write_module("bad", "utf-8", _u("\ufeff^ = 0 # %s\n") % text)
textoutput = self._run_external_case()
+ # Python 3.9 no longer prints the '\ufeff'
+ if sys.version_info >= (3,9):
+ textoutput = textoutput.replace('\ufeff', '')
self.assertThat(
textoutput,
MatchesRegex(
--
2.27.0

View File

@ -0,0 +1,45 @@
From d528842b99b16efce212e15dae3f0a54927d06d8 Mon Sep 17 00:00:00 2001
From: Cyril Roelandt <cyril@redhat.com>
Date: Fri, 19 Mar 2021 02:50:13 +0000
Subject: [PATCH] Fix tests with Python 3.10
In Python 3, error messages have become a bit more precise. For
instance, the following code snippet:
----
class Foo():
def bar(self, a):
pass
try:
Foo().bar(1, 2)
except TypeError as e:
print(e)
----
will return:
- in Python 3.9: "bar() takes 2 positional arguments but 3 were given"
- in Python 3.10: "Foo.bar() takes 2 positional arguments but 3 were
given"
Fix our tests accordingly.
---
testtools/tests/test_testsuite.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/testtools/tests/test_testsuite.py b/testtools/tests/test_testsuite.py
index 7ad5b74d..65cb88d7 100644
--- a/testtools/tests/test_testsuite.py
+++ b/testtools/tests/test_testsuite.py
@@ -181,7 +181,7 @@ def run(self):
test.run(process_result)
""", doctest.ELLIPSIS))
self.assertThat(events[3][6].decode('utf8'), DocTestMatches("""\
-TypeError: run() takes ...1 ...argument...2...given...
+TypeError: ...run() takes ...1 ...argument...2...given...
""", doctest.ELLIPSIS))
events = [event[0:10] + (None,) for event in events]
events[1] = events[1][:6] + (None,) + events[1][7:]

View File

@ -1,6 +1,6 @@
Name: python-testtools
Version: 2.4.0
Release: 1
Release: 2
Summary: Extensions to the Python unit testing framework
License: MIT
URL: https://launchpad.net/testtools
@ -10,6 +10,11 @@ BuildRequires: python3-extras python3-mimeparse python3-pbr python3-setuptools
BuildRequires: python3-traceback2 python3-testscenarios python3-sphinx python3-devel
BuildArch: noarch
Patch0: testtools-2.4.0-fix-py3-compat.patch
#Refer: https://github.com/testing-cabal/testtools/commit/254998e2e88835eaa634d9729dddcc3d4b5bc32f
#Refer: https://github.com/testing-cabal/testtools/commit/1d698cf91cb2205aedc018e465a2e17c5a6a3e94
Patch1: fix-testresult-failed.patch
#Refer: https://github.com/testing-cabal/testtools/commit/d528842b99b16efce212e15dae3f0a54927d06d8
Patch2: fix-testsuite-failed.patch
%description
Testtools is a set of extensions to the Python standard library's unit testing framework. These
@ -56,6 +61,9 @@ make PYTHON=%{__python3} check
%doc doc/_build/html/*
%changelog
* Fri Apr 2 2022 caodongxia <caodongxia@huawei.com> - 2.4.0-2
- Fix test_testresult and test_testsuite failed due to python3.10
* Fri Aug 06 2021 liusheng <liusheng2048@gmail.com> - 2.4.0-1
- Upgrade to version 2.4.0