You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But the fixture scope is a safe and sensible default for the loop_scope in my work. Lesser scopes typically won't work because the point of the fixture is to manage an async resource (not just to run async code before/after the test). The point of higher scopes in general is to create resources that can be shared between tests, so we accept the isolation implications when we write them and are happy with loop_scope = scope as a default (we can always override it if we have a use case to).
This loop_scope parameter is easily omitted, and the pytest_asyncio.fixture decorator is less known to contributors making this pattern a bit of a pain point. Is there a way I can make the loop_scope default to the fixture scope so we can continue to use @pytest.fixture(scope=<scope>) as before?
Note, I can't use the asyncio_default_fixture_loop_scope because I have fixtures with session, module, class and function scopes.
Proposal
If this can't be done at present, would it make sense to provide a asyncio_default_fixture_loop_scope = scope option?
The text was updated successfully, but these errors were encountered:
We didn't consider an option to always match loop_scope to scope. Essentially, this is the behavior when asyncio_default_fixture_loop_scope is unset, but leaving it unset gives a deprecation warning.
(in relation to #706 and other related issues)
Can I get the fixture
loop_scope
to default to the fixture's scope?Description
If I have a fixture that provides an async resource like so:
I need to declare it with
pytest_asyncio.fixture
and defineloop_scope
to match the fixturescope
(see 0.23 migration guide):But the fixture
scope
is a safe and sensible default for theloop_scope
in my work. Lesser scopes typically won't work because the point of the fixture is to manage an async resource (not just to run async code before/after the test). The point of higher scopes in general is to create resources that can be shared between tests, so we accept the isolation implications when we write them and are happy withloop_scope = scope
as a default (we can always override it if we have a use case to).This
loop_scope
parameter is easily omitted, and thepytest_asyncio.fixture
decorator is less known to contributors making this pattern a bit of a pain point. Is there a way I can make theloop_scope
default to the fixturescope
so we can continue to use@pytest.fixture(scope=<scope>)
as before?Note, I can't use the
asyncio_default_fixture_loop_scope
because I have fixtures withsession
,module
,class
andfunction
scopes.Proposal
If this can't be done at present, would it make sense to provide a
asyncio_default_fixture_loop_scope = scope
option?The text was updated successfully, but these errors were encountered: