Add note about fixture teardown and SIGTERM and SIGQUIT signals

Close #9141
This commit is contained in:
Bruno Oliveira 2021-10-01 16:12:03 -03:00
parent f65dfc39f3
commit ac3614b999
1 changed files with 17 additions and 0 deletions

View File

@ -156,3 +156,20 @@ Another good approach is by adding the data files in the ``tests`` folder.
There are also community plugins available to help to manage this aspect of
testing, e.g. `pytest-datadir <https://pypi.org/project/pytest-datadir/>`__
and `pytest-datafiles <https://pypi.org/project/pytest-datafiles/>`__.
.. _fixtures-signal-cleanup:
A note about fixture cleanup
----------------------------
pytest does not do any special processing for :data:`SIGTERM <signal.SIGTERM>` and
:data:`SIGQUIT <signal.SIGQUIT>` signals (:data:`SIGINT <signal.SIGINT>` is handled naturally
by the Python runtime via :class:`KeyboardInterrupt`), so fixtures that manage external resources which are important
to be cleared when the Python process is terminated (by those signals) might leak resources.
The reason pytest does not handle those signals to perform fixture cleanup is that signal handlers are global,
and changing them might interfere with the code under execution.
If fixtures in your suite need special care regarding termination in those scenarios,
see `this comment <https://github.com/pytest-dev/pytest/issues/5243#issuecomment-491522595>`__ in the issue
tracker for a possible workaround.