Skip to content

gh-48330: address review comments to PR-12271 #103209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Doc/library/unittest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_unittest/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -1414,15 +1414,15 @@ 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):
@unittest.skip("reason")
def test_1(self):
pass

run(Foo('test_1'), False)
run(Foo('test_1'), expect_durations=False)



Expand Down
6 changes: 5 additions & 1 deletion Lib/unittest/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down