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
```
This commit is contained in:
Ran Benita 2023-04-11 12:53:13 +03:00
parent 1b196fbeaf
commit 1b81d636e2
2 changed files with 4 additions and 0 deletions

View File

@ -0,0 +1 @@
Python 3.12 support: fixed ``RuntimeError: TestResult has no addDuration method`` when running ``unittest`` tests.

View File

@ -298,6 +298,9 @@ class TestCaseFunction(Function):
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