Skip to content
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

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

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions Doc/library/unittest.rst
Expand Up @@ -390,7 +390,7 @@
widget = Widget('The widget')
self.assertEqual(widget.size(), (50, 50))

Note that in order to test something, we use one of the :meth:`assert\*`

Check warning on line 393 in Doc/library/unittest.rst

GitHub Actions / Docs

py:meth reference target not found: assert*
methods provided by the :class:`TestCase` base class. If the test fails, an
exception will be raised with an explanatory message, and :mod:`unittest`
will identify the test case as a :dfn:`failure`. Any other exceptions will be
Expand Down Expand Up @@ -440,7 +440,7 @@
If :meth:`~TestCase.setUp` succeeded, :meth:`~TestCase.tearDown` will be
run whether the test method succeeded or not.

Such a working environment for the testing code is called a

Check warning on line 443 in Doc/library/unittest.rst

GitHub Actions / Docs

py:meth reference target not found: TestCase.__init__
:dfn:`test fixture`. A new TestCase instance is created as a unique
test fixture used to execute each individual test method. Thus
:meth:`~TestCase.setUp`, :meth:`~TestCase.tearDown`, and :meth:`~TestCase.__init__`
Expand Down Expand Up @@ -522,7 +522,7 @@
not recommended. Taking the time to set up proper :class:`TestCase`
subclasses will make future test refactorings infinitely easier.

In some cases, the existing tests may have been written using the :mod:`doctest`

Check warning on line 525 in Doc/library/unittest.rst

GitHub Actions / Docs

py:class reference target not found: DocTestSuite
module. If so, :mod:`doctest` provides a :class:`DocTestSuite` class that can
automatically build :class:`unittest.TestSuite` instances from the existing
:mod:`doctest`\ -based tests.
Expand Down Expand Up @@ -636,7 +636,7 @@
Usually you can use :meth:`TestCase.skipTest` or one of the skipping
decorators instead of raising this directly.

Skipped tests will not have :meth:`~TestCase.setUp` or :meth:`~TestCase.tearDown` run around them.

Check warning on line 639 in Doc/library/unittest.rst

GitHub Actions / Docs

py:func reference target not found: setUpModule

Check warning on line 639 in Doc/library/unittest.rst

GitHub Actions / Docs

py:func reference target not found: tearDownModule
Skipped classes will not have :meth:`~TestCase.setUpClass` or :meth:`~TestCase.tearDownClass` run.
Skipped modules will not have :func:`setUpModule` or :func:`tearDownModule` run.

Expand Down Expand Up @@ -1012,7 +1012,7 @@
When used as a context manager, :meth:`assertRaises` accepts the
additional keyword argument *msg*.

The context manager will store the caught exception object in its

Check warning on line 1015 in Doc/library/unittest.rst

GitHub Actions / Docs

py:attr reference target not found: exception
:attr:`exception` attribute. This can be useful if the intention
is to perform additional checks on the exception raised::

Expand All @@ -1026,7 +1026,7 @@
Added the ability to use :meth:`assertRaises` as a context manager.

.. versionchanged:: 3.2
Added the :attr:`exception` attribute.

Check warning on line 1029 in Doc/library/unittest.rst

GitHub Actions / Docs

py:attr reference target not found: exception

.. versionchanged:: 3.3
Added the *msg* keyword argument when used as a context manager.
Expand Down Expand Up @@ -1078,7 +1078,7 @@
When used as a context manager, :meth:`assertWarns` accepts the
additional keyword argument *msg*.

The context manager will store the caught warning object in its

Check warning on line 1081 in Doc/library/unittest.rst

GitHub Actions / Docs

py:attr reference target not found: warning

Check warning on line 1081 in Doc/library/unittest.rst

GitHub Actions / Docs

py:attr reference target not found: filename

Check warning on line 1081 in Doc/library/unittest.rst

GitHub Actions / Docs

py:attr reference target not found: lineno
:attr:`warning` attribute, and the source line which triggered the
warnings in the :attr:`filename` and :attr:`lineno` attributes.
This can be useful if the intention is to perform additional checks
Expand Down Expand Up @@ -2191,10 +2191,6 @@
.. 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
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
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