Skip to content

gh-122196: Clarify, reorder language for TestCase(object) #24465

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 13 additions & 10 deletions Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,21 @@ 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'.

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
Test authors may invoke unittest.main() from the subclass's "__name__ guard"
section to run all methods defined in the test class. Alternatively,
test authors may subclass this TestCase class for their own tests.
Testing code may be placed in subclass method named 'runTest';
To achieve more precise subclass test invocation see below (viz.,
constructor kwarg).

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'
parameter 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 Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The former docstring for `TestCase(object)` inappropriately uses the technical term 'fixture' before introducing or defining it. This violates the principle of term definition prior to usage. Therefore, I have re-arranged the description so that the definition comes before the usage. Additional semantic changes made to be clearer, more understandable, and linear.
Loading