Skip to content
Closed
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
18 changes: 11 additions & 7 deletions Doc/library/unittest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2361,17 +2361,20 @@ Class and Module Fixtures
-------------------------

Class and module level fixtures are implemented in :class:`TestSuite`. When
the test suite encounters a test from a new class then :meth:`tearDownClass`
from the previous class (if there is one) is called, followed by
Copy link
Member

Choose a reason for hiding this comment

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

Why removing the "if there is one"? It was right:

tearDownClass = getattr(previousClass, 'tearDownClass', None)
if tearDownClass is not None:
    ...

I don't see any problem with this paragraph, and it looks not correlated with bpo-36612.

the test suite encounters a test that is from a different class from the previous
test, then :meth:`tearDownClass` from the previous class is called, followed by
:meth:`setUpClass` from the new class.

Similarly if a test is from a different module from the previous test then
``tearDownModule`` from the previous module is run, followed by
Similarly if a test is from a different module from the previous test, then
``tearDownModule`` from the previous module is called, followed by
``setUpModule`` from the new module.

After all the tests have run the final ``tearDownClass`` and
``tearDownModule`` are run.

The abovementioned calls are only executed,
if the corresponding method or function is found.
Copy link
Author

Choose a reason for hiding this comment

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

Choosing "method is found", instead of "method exists" or "class has a method", in order to hint method resolution order is in effect.


Note that shared fixtures do not play well with [potential] features like test
parallelization and they break test isolation. They should be used with care.

Expand Down Expand Up @@ -2410,9 +2413,10 @@ These must be implemented as class methods::
def tearDownClass(cls):
cls._connection.destroy()

If you want the ``setUpClass`` and ``tearDownClass`` on base classes called
then you must call up to them yourself. The implementations in
:class:`TestCase` are empty.
The implementations in :class:`TestCase` are present, but empty.
Copy link
Member

Choose a reason for hiding this comment

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

This sentence is right, the implementations are present but empty. But now without context I don't see the point of mentioning it, why not removing it all?

Copy link
Author

Choose a reason for hiding this comment

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

I will expand in next version.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly this still doesn't sound very useful to me. The new text doesn't really answer the question in the original bug report.

That means the implemenation is executed for classes descending from
Copy link
Author

Choose a reason for hiding this comment

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

Choosing "descending" instead of "derived" or "child", to suggest the inheritance graphs can be complicated.

:class:`TestCase`, but the implementation does not do anything,
Copy link
Author

Choose a reason for hiding this comment

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

Empty implementation executed means no special handling is there to interfere with normal inheritance rules.

unless overriden as in the example.

If an exception is raised during a ``setUpClass`` then the tests in the class
are not run and the ``tearDownClass`` is not run. Skipped classes will not
Expand Down
Loading