Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

loop_scope default #1095

Open
Feature
@oliver-sanders

Description

@oliver-sanders

(in relation to#706 and other related issues)

Can I get the fixtureloop_scope to default to the fixture's scope?

Description

If I have a fixture that provides an async resource like so:

@pytest.fixture(scope='module')asyncdefmy_async_fixture():yieldmy_async_resource()

I need to declare it withpytest_asyncio.fixture and defineloop_scope to match the fixturescope (see0.23 migration guide):

@pytest_asyncio.fixture(scope='module',loop_scope='module')asyncdefmy_async_fixture():yieldmy_async_resource()

But the fixturescope 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).

Thisloop_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 theasyncio_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 aasyncio_default_fixture_loop_scope = scope option?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp