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