Skip to content

Commit

Permalink
unittest: add addDuration function for Python 3.12 support
Browse files Browse the repository at this point in the history
Fix #10875

Without this, fails with

```
...
E           AttributeError: 'TestCaseFunction' object has no attribute 'addDuration'
...
E           RuntimeWarning: TestResult has no addDuration method
```
  • Loading branch information
bluetech committed Apr 11, 2023
1 parent 1b196fb commit 1b81d63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/10875.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 3.12 support: fixed ``RuntimeError: TestResult has no addDuration method`` when running ``unittest`` tests.
3 changes: 3 additions & 0 deletions src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 302 in src/_pytest/unittest.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/unittest.py#L302

Added line #L302 was not covered by tests

def runtest(self) -> None:
from _pytest.debugging import maybe_wrap_pytest_function_for_tracing

Expand Down

0 comments on commit 1b81d63

Please sign in to comment.