rework examples and edit copy
This commit is contained in:
parent
059447cecd
commit
fd316339ed
|
@ -741,8 +741,8 @@ does offer some nuances for when you're in a pinch.
|
||||||
Note on finalizer order
|
Note on finalizer order
|
||||||
""""""""""""""""""""""""
|
""""""""""""""""""""""""
|
||||||
|
|
||||||
Finalizers are executed in a first-in-last-out order, while operations after yield are executed sequentially.
|
Finalizers are executed in a first-in-last-out order.
|
||||||
Consider the differences in the following examples:
|
For yield fixtures, the first fixture to run is the right-most one, i.e. the last test parameter.
|
||||||
|
|
||||||
.. regendoc:wipe
|
.. regendoc:wipe
|
||||||
|
|
||||||
|
@ -751,7 +751,6 @@ Consider the differences in the following examples:
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def test_bar(fix_w_yield1, fix_w_yield2):
|
def test_bar(fix_w_yield1, fix_w_yield2):
|
||||||
print("test_bar")
|
print("test_bar")
|
||||||
|
|
||||||
|
@ -780,6 +779,9 @@ Consider the differences in the following examples:
|
||||||
after_yield_1
|
after_yield_1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
For finalizers, the first fixture to run is last call to `request.addfinalizer`.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -791,7 +793,6 @@ Consider the differences in the following examples:
|
||||||
request.addfinalizer(partial(print, "finalizer_1"))
|
request.addfinalizer(partial(print, "finalizer_1"))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def test_bar(fix_w_finalizers):
|
def test_bar(fix_w_finalizers):
|
||||||
print("test_bar")
|
print("test_bar")
|
||||||
|
|
||||||
|
@ -807,6 +808,8 @@ Consider the differences in the following examples:
|
||||||
.finalizer_1
|
.finalizer_1
|
||||||
finalizer_2
|
finalizer_2
|
||||||
|
|
||||||
|
This is so because yield fixtures use addfinalizer behind the scenes: when the fixture executes, addfinalizer registers a function that resumes the generator, which in turn calls the teardown code.
|
||||||
|
|
||||||
|
|
||||||
.. _`safe teardowns`:
|
.. _`safe teardowns`:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue