remove scope argument from request.addfinalizer
--HG-- branch : 1.0.x
This commit is contained in:
@@ -120,7 +120,27 @@ to access test configuration and test context:
|
||||
``request.param``: if exists was passed by a `parametrizing test generator`_
|
||||
|
||||
|
||||
perform scoped setup and teardown
|
||||
teardown/cleanup after test function execution
|
||||
------------------------------------------------
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
def addfinalizer(func):
|
||||
""" call a finalizer function when test function finishes. """
|
||||
|
||||
Calling ``request.addfinalizer()`` is useful for scheduling teardown
|
||||
functions. Here is an example for providing a ``myfile``
|
||||
object that is to be closed when the test function finishes.
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
def pytest_funcarg__myfile(self, request):
|
||||
# ... create and open a unique per-function "myfile" object ...
|
||||
request.addfinalizer(lambda: myfile.close())
|
||||
return myfile
|
||||
|
||||
|
||||
perform scope-specific setup and cleanup
|
||||
---------------------------------------------
|
||||
|
||||
.. sourcecode:: python
|
||||
@@ -148,30 +168,6 @@ example for providing a value that is to be setup only once during a test run:
|
||||
)
|
||||
|
||||
|
||||
cleanup after test function execution
|
||||
---------------------------------------------
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
def addfinalizer(func, scope="function"):
|
||||
""" register calling a a finalizer function.
|
||||
scope == 'function': when the single test function run finishes.
|
||||
scope == 'module': when tests in a different module are run
|
||||
scope == 'session': when tests of the session have run.
|
||||
"""
|
||||
|
||||
Calling ``request.addfinalizer()`` is useful for scheduling teardown
|
||||
functions. The given scope determines when the teardown function
|
||||
will be called. Here is a basic example for providing a ``myfile``
|
||||
object that is to be closed when the test function finishes.
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
def pytest_funcarg__myfile(self, request):
|
||||
# ... create and open a unique per-function "myfile" object ...
|
||||
request.addfinalizer(lambda: myfile.close())
|
||||
return myfile
|
||||
|
||||
requesting values of other funcargs
|
||||
---------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user