mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-24412: Adds cleanUps for setUpClass and setUpModule. (GH-9190)
This commit is contained in:
parent
49fa4a9f1e
commit
0f221d09ca
7 changed files with 783 additions and 18 deletions
|
|
@ -1448,6 +1448,39 @@ Test cases
|
|||
|
||||
.. versionadded:: 3.1
|
||||
|
||||
.. classmethod:: addClassCleanup(function, *args, **kwargs)
|
||||
|
||||
Add a function to be called after :meth:`tearDownClass` to cleanup
|
||||
resources used during the test class. Functions will be called in reverse
|
||||
order to the order they are added (:abbr:`LIFO (last-in, first-out)`).
|
||||
They are called with any arguments and keyword arguments passed into
|
||||
:meth:`addClassCleanup` when they are added.
|
||||
|
||||
If :meth:`setUpClass` fails, meaning that :meth:`tearDownClass` is not
|
||||
called, then any cleanup functions added will still be called.
|
||||
|
||||
.. versionadded:: 3.8
|
||||
|
||||
|
||||
.. classmethod:: doClassCleanups()
|
||||
|
||||
This method is called unconditionally after :meth:`tearDownClass`, or
|
||||
after :meth:`setUpClass` if :meth:`setUpClass` raises an exception.
|
||||
|
||||
It is responsible for calling all the cleanup functions added by
|
||||
:meth:`addCleanupClass`. If you need cleanup functions to be called
|
||||
*prior* to :meth:`tearDownClass` then you can call
|
||||
:meth:`doCleanupsClass` yourself.
|
||||
|
||||
:meth:`doCleanupsClass` pops methods off the stack of cleanup
|
||||
functions one at a time, so it can be called at any time.
|
||||
|
||||
.. versionadded:: 3.8
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.. class:: FunctionTestCase(testFunc, setUp=None, tearDown=None, description=None)
|
||||
|
||||
|
|
@ -2268,6 +2301,38 @@ module will be run and the ``tearDownModule`` will not be run. If the exception
|
|||
:exc:`SkipTest` exception then the module will be reported as having been skipped
|
||||
instead of as an error.
|
||||
|
||||
To add cleanup code that must be run even in the case of an exception, use
|
||||
``addModuleCleanup``:
|
||||
|
||||
|
||||
.. function:: addModuleCleanup(function, *args, **kwargs)
|
||||
|
||||
Add a function to be called after :func:`tearDownModule` to cleanup
|
||||
resources used during the test class. Functions will be called in reverse
|
||||
order to the order they are added (:abbr:`LIFO (last-in, first-out)`).
|
||||
They are called with any arguments and keyword arguments passed into
|
||||
:meth:`addModuleCleanup` when they are added.
|
||||
|
||||
If :meth:`setUpModule` fails, meaning that :func:`tearDownModule` is not
|
||||
called, then any cleanup functions added will still be called.
|
||||
|
||||
.. versionadded:: 3.8
|
||||
|
||||
|
||||
.. function:: doModuleCleanups()
|
||||
|
||||
This function is called unconditionally after :func:`tearDownModule`, or
|
||||
after :func:`setUpModule` if :func:`setUpModule` raises an exception.
|
||||
|
||||
It is responsible for calling all the cleanup functions added by
|
||||
:func:`addCleanupModule`. If you need cleanup functions to be called
|
||||
*prior* to :func:`tearDownModule` then you can call
|
||||
:func:`doModuleCleanups` yourself.
|
||||
|
||||
:func:`doModuleCleanups` pops methods off the stack of cleanup
|
||||
functions one at a time, so it can be called at any time.
|
||||
|
||||
.. versionadded:: 3.8
|
||||
|
||||
Signal Handling
|
||||
---------------
|
||||
|
|
|
|||
|
|
@ -233,6 +233,15 @@ unicodedata
|
|||
is in a specific normal form. (Contributed by Max Belanger and David Euresti in
|
||||
:issue:`32285`).
|
||||
|
||||
unittest
|
||||
--------
|
||||
|
||||
* Added :func:`~unittest.addModuleCleanup()` and
|
||||
:meth:`~unittest.TestCase.addClassCleanup()` to unittest to support
|
||||
cleanups for :func:`~unittest.setUpModule()` and
|
||||
:meth:`~unittest.TestCase.setUpClass()`.
|
||||
(Contributed by Lisa Roach in :issue:`24412`.)
|
||||
|
||||
venv
|
||||
----
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue