'How to add arguments to the function passed in request.addfinalizer() of pytest?
I am writing a test suite with pytest. It looks like this.
@pytest.fixture
def f(request):
...
def fin(arg):
...
return
request.addfinalizer(fin)
I am wondering if 'arg' would be taken into account inside off 'addfinalizer'? Or is it a way to do that?
Solution 1:[1]
use a functools.partial or a lambda
Solution 2:[2]
You can pass a lambda like this:
@pytest.fixture
def f(request):
...
def fin(arg):
...
return
request.addfinalizer(lambda: fin(some_arg_here))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | lucrib |
