]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-48330: address review comments to PR-12271 (#103209)
authorGiampaolo Rodola <g.rodola@gmail.com>
Sun, 16 Apr 2023 22:19:44 +0000 (00:19 +0200)
committerGitHub <noreply@github.com>
Sun, 16 Apr 2023 22:19:44 +0000 (00:19 +0200)
address review comments to PR-12271

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Doc/library/unittest.rst
Lib/test/test_unittest/test_runner.py
Lib/unittest/result.py

index d1a977fd7da6a5abf5bdf6bac37a78883ab609db..a7c74cfa4fb477ec6f9a0964ac8484b9bae688af 100644 (file)
@@ -2191,10 +2191,6 @@ Loading and running tests
    .. versionadded:: 3.12
       Added *durations* keyword argument.
 
-   .. versionchanged:: 3.12
-      Subclasses should accept ``**kwargs`` to ensure compatibility as the
-      interface changes.
-
 .. data:: defaultTestLoader
 
    Instance of the :class:`TestLoader` class intended to be shared.  If no
index 1ce42a106c5883ed2d1188bdd673b28509ce29ce..ceb4c8acde532cd088f56094e1c270173434b9c0 100644 (file)
@@ -1367,7 +1367,7 @@ class Test_TextTestRunner(unittest.TestCase):
         self.assertTrue(runner.stream.stream is f)
 
     def test_durations(self):
-        def run(test, expect_durations):
+        def run(test, *, expect_durations=True):
             stream = BufferedWriter()
             runner = unittest.TextTestRunner(stream=stream, durations=5, verbosity=2)
             result = runner.run(test)
@@ -1389,21 +1389,21 @@ class Test_TextTestRunner(unittest.TestCase):
             def test_1(self):
                 pass
 
-        run(Foo('test_1'), True)
+        run(Foo('test_1'), expect_durations=True)
 
         # failure
         class Foo(unittest.TestCase):
             def test_1(self):
                 self.assertEqual(0, 1)
 
-        run(Foo('test_1'), True)
+        run(Foo('test_1'), expect_durations=True)
 
         # error
         class Foo(unittest.TestCase):
             def test_1(self):
                 1 / 0
 
-        run(Foo('test_1'), True)
+        run(Foo('test_1'), expect_durations=True)
 
 
         # error in setUp and tearDown
@@ -1414,7 +1414,7 @@ class Test_TextTestRunner(unittest.TestCase):
             def test_1(self):
                 pass
 
-        run(Foo('test_1'), True)
+        run(Foo('test_1'), expect_durations=True)
 
         # skip (expect no durations)
         class Foo(unittest.TestCase):
@@ -1422,7 +1422,7 @@ class Test_TextTestRunner(unittest.TestCase):
             def test_1(self):
                 pass
 
-        run(Foo('test_1'), False)
+        run(Foo('test_1'), expect_durations=False)
 
 
 
index fa9bea47c88829b8aa44baee2b23c1ba3ab301e0..7757dba9670b43a16e7e94e8208b7a1f1dcec6d3 100644 (file)
@@ -159,7 +159,11 @@ class TestResult(object):
         self.unexpectedSuccesses.append(test)
 
     def addDuration(self, test, elapsed):
-        """Called when a test finished to run, regardless of its outcome."""
+        """Called when a test finished to run, regardless of its outcome.
+        *test* is the test case corresponding to the test method.
+        *elapsed* is the time represented in seconds, and it includes the
+        execution of cleanup functions.
+        """
         # support for a TextTestRunner using an old TestResult class
         if hasattr(self, "collectedDurations"):
             self.collectedDurations.append((test, elapsed))