re-add finalizers examples

This commit is contained in:
Adrián Aizpurua 2022-07-27 19:10:59 +02:00
parent b61b6138ec
commit 059447cecd
1 changed files with 28 additions and 8 deletions

View File

@ -768,6 +768,32 @@ Consider the differences in the following examples:
print("after_yield_2") print("after_yield_2")
.. code-block:: pytest
$ pytest test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-7.x.y, pluggy-1.x.y
collected 1 item
test_module.py test_bar
.after_yield_2
after_yield_1
.. code-block:: python
import pytest
@pytest.fixture
def fix_w_finalizers(request):
request.addfinalizer(partial(print, "finalizer_2"))
request.addfinalizer(partial(print, "finalizer_1"))
@pytest.fixture
def test_bar(fix_w_finalizers):
print("test_bar")
.. code-block:: pytest .. code-block:: pytest
@ -775,18 +801,12 @@ Consider the differences in the following examples:
$ pytest test_module.py $ pytest test_module.py
=========================== test session starts ============================ =========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-7.x.y, pluggy-1.x.y platform linux -- Python 3.x.y, pytest-7.x.y, pluggy-1.x.y
collected 2 items collected 1 item
main.py test_module.py test_bar
test_foo
.finalizer_1 .finalizer_1
finalizer_2 finalizer_2
test_bar
.after_yield_1
after_yield_2
.. _`safe teardowns`: .. _`safe teardowns`: