-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
De-emphaze addfinalizer in favour of ExitStack #5587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
now that py2 support is dropped a handy little fixture that might be worth being built in: @pytest.fixture
def exit_stack():
with contextlib.ExitStack() as exit_stack:
yield exit_stack can be used as: def test_foo(exit_stack):
v = exit_stack.enter_context(cm)
...
some_service = Service()
exit_stack.callback(some_service.disconnect) or maybe https://docs.pytest.org/en/latest/reference.html#_pytest.fixtures.FixtureRequest could expose an @pytest.fixture
def equipments(request):
r = []
for port in ('C1', 'C3', 'C28'):
equip = connect(port)
request.exit_stack.callback(equip.disconnect)
r.append(equip)
return r |
or maybe we should discourage addfinalizer entirely and suggest people make their own ExitStack in a yield fixture? @pytest.fixture
def equipments():
with contextlib.ExitStack() as exit_stack:
r = []
for port in ('C1', 'C3', 'C28'):
equip = connect(port)
exit_stack.callback(equip.disconnect)
r.append(equip)
yield r |
Not sure, |
de-emphasize request.addfinalizer Fixes #5587
now that py2 support is dropped we should discourage addfinalizer and suggest people make their own ExitStack in a yield fixture
The text was updated successfully, but these errors were encountered: