TestResult decorator classes do not have the addDuration method added to TestResult in Python 3.12

Bug #2045171 reported by Will
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
subunit
New
Undecided
Unassigned

Bug Description

Python 3.12 added [[https://docs.python.org/3/library/unittest.html#unittest.TestResult.addDuration | an addDuration method]]. The unittest test runner tries to use this method now and triggers a warning if it is not present. I specifically encounter this warning when using stestr which wraps test results with AutoTimingTestResultDectorator (see [[https://github.com/mtreinish/stestr/blob/cc66736df90968126585540b220fea663b124bbf/stestr/subunit_runner/run.py#L44-L45 | here]]). An example of a project where this warning is generated like this is rustworkx. [[https://github.com/Qiskit/rustworkx/actions/runs/7012357436/job/19076767764 | Here]] is a CI log with the warning generated.

A simpler reproducer is to use {{{stestr -t . run test}}} with a test.py file with this content (tested with stestr 4.1.0):

{{{#!python
from unittest import TestCase

class TestExample(TestCase):
    def test_pass(self):
        pass
}}}

Will (wsha)
description: updated
Revision history for this message
Will (wsha) wrote :

Since there is an overlap of maintainers with testtools, I will mention here that I think classes like ExtendedToStreamDecorator in testtools might also need to add addDuration, but it is less clear to me if those classes are supposed to mirror the unittest.TestResult interface or just work with the testtools classes, so I won't open an issue for them now.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.