Skip to content
Open
Changes from 2 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
24 changes: 13 additions & 11 deletions Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,20 @@ def __iter__(self):
class TestCase(object):
"""A class whose instances are single test cases.

By default, the test code itself should be placed in a method named
'runTest'.
Test authors should subclass this TestCase class for their own tests.
Testing code may be placed in subclass method named 'runTest';
alternatively, invoke unittest.main() from the subclass's "__name__ guard"
section to run all methods defined in the test class. To achieve more
precise subclass test invocation see below (viz., constructor kwarg).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runTest form is far rarer, should we cover it second?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote the docs according to your suggestion.


If the fixture may be used for many test cases, create as
many test methods as are needed. When instantiating such a TestCase
subclass, specify in the constructor arguments the name of the test method
that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction
and deconstruction of the test's environment ('fixture') can be
Construction and destruction of the tests' environment ('fixture') can be
implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If the fixture will be used for several distinct test cases, create as
many test methods as needed in the TestCase subclass, then specify a
method to execute by providing the method name in the 'methodName'
kwarg of the instance constructor.

If it is necessary to override the __init__ method, the base class
__init__ method must always be called. It is important that subclasses
should not change the signature of their __init__ method, since instances
Expand All @@ -385,8 +387,8 @@ class TestCase(object):
the instance's assertion methods fail; test methods raising this
exception will be deemed to have 'failed' rather than 'errored'.
* longMessage: determines whether long messages (including repr of
objects used in assert methods) will be printed on failure in *addition*
to any explicit message passed.
objects used in assert methods) will be printed on failure in
*addition* to any explicit message passed.
* maxDiff: sets the maximum length of a diff in failure messages
by assert methods using difflib. It is looked up as an instance
attribute so can be configured by individual tests if required.
Expand Down