[Python-checkins] gh-48330: address review comments to PR-12271 (#103209)
giampaolo
webhook-mailer at python.org
Sun Apr 16 18:19:51 EDT 2023
https://github.com/python/cpython/commit/ff3303e49c13495d8d9cf1dc0cf0624bbda1d3ae
commit: ff3303e49c13495d8d9cf1dc0cf0624bbda1d3ae
branch: main
author: Giampaolo Rodola <g.rodola at gmail.com>
committer: giampaolo <g.rodola at gmail.com>
date: 2023-04-17T00:19:44+02:00
summary:
gh-48330: address review comments to PR-12271 (#103209)
address review comments to PR-12271
Signed-off-by: Giampaolo Rodola <g.rodola at gmail.com>
files:
M Doc/library/unittest.rst
M Lib/test/test_unittest/test_runner.py
M Lib/unittest/result.py
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index d1a977fd7da6..a7c74cfa4fb4 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -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
diff --git a/Lib/test/test_unittest/test_runner.py b/Lib/test/test_unittest/test_runner.py
index 1ce42a106c58..ceb4c8acde53 100644
--- a/Lib/test/test_unittest/test_runner.py
+++ b/Lib/test/test_unittest/test_runner.py
@@ -1367,7 +1367,7 @@ def testSpecifiedStreamUsed(self):
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 Foo(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 @@ def setUp(self):
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 Foo(unittest.TestCase):
def test_1(self):
pass
- run(Foo('test_1'), False)
+ run(Foo('test_1'), expect_durations=False)
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
index fa9bea47c888..7757dba9670b 100644
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -159,7 +159,11 @@ def addUnexpectedSuccess(self, test):
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))
More information about the Python-checkins
mailing list