Merge pull request #9150 from nicoddemus/issue-9141-fixture-docs

This commit is contained in:
Bruno Oliveira 2021-10-04 09:48:19 -03:00 committed by GitHub
commit c4557c3192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.