From ec0e1eba6dccb165b625461863bb746ad887f7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= Date: Thu, 13 Apr 2023 12:11:12 +0200 Subject: [PATCH] unittest: add addDuration function for Python 3.12 support --- 1b81d63.patch | 42 ++++++++++++++++++++++++++++++++++++++++++ pytest.spec | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 1b81d63.patch diff --git a/1b81d63.patch b/1b81d63.patch new file mode 100644 index 0000000..96e3142 --- /dev/null +++ b/1b81d63.patch @@ -0,0 +1,42 @@ +From 1b81d636e2a086403031909cfb71a397d1ce26de Mon Sep 17 00:00:00 2001 +From: Ran Benita +Date: Tue, 11 Apr 2023 12:53:13 +0300 +Subject: [PATCH] unittest: add addDuration function for Python 3.12 support + +Fix #10875 + +Without this, fails with + +``` +... +E AttributeError: 'TestCaseFunction' object has no attribute 'addDuration' +... +E RuntimeWarning: TestResult has no addDuration method +``` +--- + changelog/10875.improvement.rst | 1 + + src/_pytest/unittest.py | 3 +++ + 2 files changed, 4 insertions(+) + create mode 100644 changelog/10875.improvement.rst + +diff --git a/changelog/10875.improvement.rst b/changelog/10875.improvement.rst +new file mode 100644 +index 0000000000..eeaf046350 +--- /dev/null ++++ b/changelog/10875.improvement.rst +@@ -0,0 +1 @@ ++Python 3.12 support: fixed ``RuntimeError: TestResult has no addDuration method`` when running ``unittest`` tests. +diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py +index c2df986530..c660aa75db 100644 +--- a/src/_pytest/unittest.py ++++ b/src/_pytest/unittest.py +@@ -298,6 +298,9 @@ def addSuccess(self, testcase: "unittest.TestCase") -> None: + def stopTest(self, testcase: "unittest.TestCase") -> None: + pass + ++ def addDuration(self, testcase: "unittest.TestCase", elapsed: float) -> None: ++ pass ++ + def runtest(self) -> None: + from _pytest.debugging import maybe_wrap_pytest_function_for_tracing + diff --git a/pytest.spec b/pytest.spec index e0696ca..3a3aa07 100644 --- a/pytest.spec +++ b/pytest.spec @@ -10,6 +10,9 @@ Source: %{pypi_source pytest %{base_version}%{?prerelease}} # see https://github.com/pytest-dev/pytest/issues/10042#issuecomment-1237132867 Patch: pytest-7.1.3-fix-xfails.patch +# unittest: add addDuration function for Python 3.12 support +Patch: https://github.com/pytest-dev/pytest/commit/1b81d63.patch + # Remove -s from Python shebang, # ensure that packages installed with pip to user locations are testable # https://bugzilla.redhat.com/2152171