diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 55c79d353539ca..7921b21687161b 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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 diff --git a/Misc/NEWS.d/next/Documentation/2024-07-23-20-18-31.gh-issue-122196.pYwrvo.rst b/Misc/NEWS.d/next/Documentation/2024-07-23-20-18-31.gh-issue-122196.pYwrvo.rst new file mode 100644 index 00000000000000..29c3f8426fc487 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2024-07-23-20-18-31.gh-issue-122196.pYwrvo.rst @@ -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.