Skip to content

Commit dff4675

Browse files
authored
bpo-19950: Clarify unittest TestCase instance use. (GH-6875)
1 parent 3ab0136 commit dff4675

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Doc/library/unittest.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ testing code::
361361

362362
Note that in order to test something, we use one of the :meth:`assert\*`
363363
methods provided by the :class:`TestCase` base class. If the test fails, an
364-
exception will be raised, and :mod:`unittest` will identify the test case as a
365-
:dfn:`failure`. Any other exceptions will be treated as :dfn:`errors`.
364+
exception will be raised with an explanatory message, and :mod:`unittest`
365+
will identify the test case as a :dfn:`failure`. Any other exceptions will be
366+
treated as :dfn:`errors`.
366367

367368
Tests can be numerous, and their set-up can be repetitive. Luckily, we
368369
can factor out set-up code by implementing a method called
@@ -408,13 +409,18 @@ after the test method has been run::
408409
If :meth:`~TestCase.setUp` succeeded, :meth:`~TestCase.tearDown` will be
409410
run whether the test method succeeded or not.
410411

411-
Such a working environment for the testing code is called a :dfn:`fixture`.
412-
413-
Test case instances are grouped together according to the features they test.
414-
:mod:`unittest` provides a mechanism for this: the :dfn:`test suite`,
415-
represented by :mod:`unittest`'s :class:`TestSuite` class. In most cases,
416-
calling :func:`unittest.main` will do the right thing and collect all the
417-
module's test cases for you, and then execute them.
412+
Such a working environment for the testing code is called a
413+
:dfn:`test fixture`. A new TestCase instance is created as a unique
414+
test fixture used to execute each individual test method. Thus
415+
`~TestCase.setUp`, `~TestCase.tearDown`, and `~TestCase.__init__`
416+
will be called once per test.
417+
418+
It is recommended that you use TestCase implementations to group tests together
419+
according to the features they test. :mod:`unittest` provides a mechanism for
420+
this: the :dfn:`test suite`, represented by :mod:`unittest`'s
421+
:class:`TestSuite` class. In most cases, calling :func:`unittest.main` will do
422+
the right thing and collect all the module's test cases for you and execute
423+
them.
418424

419425
However, should you want to customize the building of your test suite,
420426
you can do it yourself::

0 commit comments

Comments
 (0)