Open RonnyPfannschmidt opened 2 weeks ago
I understand the rationale, but in those cases I think a reasonable workaround is to refactor the fixture code into a contextmanager, and use that in the fixture:
@contextmanager
def managed_resource(manager, login_data):
with manager.client(login_data) as client:
yield client
@fixture(name="managed_resource")
def managed_resource_fixture(manager, login_data):
with my_managed_resource(manager, login_data):
yield client
Not sure we need to add this to the pytest core, given this is not common occurrence (at least in my experience).
My 2 cents
What's the problem this feature will solve?
unlike normal context managers, fixtures functions cannot easily be used in a manual way as a contextmanager
Describe the solution you'd like
Alternative Solutions
wrapping a fixtures function into contextmanager as api makes for a ugly api