Skip to content

fix(ci): set the pytest-asyncio default fixture loop scope #5384

Open

Description

@dan-petty

Problem Description

Each uv run devops ci test run prints a PytestDeprecationWarning from pytest-asyncio one time for each xdist worker. The warning says that the option asyncio_default_fixture_loop_scope is unset. [tool.pytest.ini_options] in pyproject.toml sets asyncio_mode = "auto" but does not set asyncio_default_fixture_loop_scope. The pin pytest-asyncio==1.4.1.post1 came with #5102. The warning adds noise to each narrowed test run, and a later pytest-asyncio release changes the default scope.

Reproduction Steps

  1. On origin/main, run uv run devops ci test tests/commands/test_review_pr_post.py.
  2. Read the output before the test progress line.

Expected vs Actual Behavior

Expected: the test run prints no deprecation warning from the pytest configuration of the project.

Actual: the run prints this warning once for each worker:

.venv/lib/python3.14/site-packages/pytest_asyncio/plugin.py:300: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the "fixture" caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to "function" scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future.

Environment Diagnostics

origin/main at release 0.127.0 (2026-11-13), Python 3.14, pytest-asyncio 1.4.1.post1, devcontainer. Found during the review of #5346.

Logs, Traces, or Terminal Output

The fix is probably one line in [tool.pytest.ini_options]: asyncio_default_fixture_loop_scope = "function". Make sure that no async fixture needs a wider scope first.

Alternatives check of 2026-11-22: in-use.
The repository already uses this tool.
Tool: pytest-dev/pytest-asyncio (https://github.com/pytest-dev/pytest-asyncio), Apache-2.0, last activity 2026-11-18, maintained.
Reason: Searches on the option returned no useful result, but the plugin's repository and PyPI entry confirm pytest-asyncio owns the setting the warning names, so one ini line is the whole fix.

Covers:

  • Declares the async fixture loop scope through an ini option
  • Stops the deprecation warning once the option is set
  • Keeps the scope that the next release defaults to

Lacks:

  • Picks no scope value for the project by itself
  • No check that a fixture needs a wider scope
  • No proof the suite passes under the function scope

Proposed design

Problem statement

Each uv run devops ci test run prints a PytestDeprecationWarning for each xdist worker. The cause is that [tool.pytest.ini_options] leaves asyncio_default_fixture_loop_scope unset. The warning adds noise to each narrowed run, and a later pytest-asyncio release changes the fixture loop scope. The change sets the option to function and confirms the suite with a full run.

Acceptance criteria

Requirement: The default fixture loop scope is explicit

The [tool.pytest.ini_options] table in pyproject.toml SHALL set asyncio_default_fixture_loop_scope to function.

Scenario: A narrowed test run prints no deprecation warning

  • WHEN uv run devops ci test tests/commands/test_review_pr_post.py runs on the changed tree.
  • THEN the run exits 0 and its output holds no PytestDeprecationWarning that names asyncio_default_fixture_loop_scope.

Requirement: The suite passes under the function scope

Each async fixture of the test suite MUST still pass when its event loop scope is function.

Scenario: The full suite passes

  • WHEN uv run devops ci test runs the full suite on the changed tree.
  • THEN the run exits 0 and its pytest summary reports no failed test and no error.

Existing Tool Considered

pytest-asyncio, https://github.com/pytest-dev/pytest-asyncio: verdict in-use. The repository already depends on the plugin, and no ADR rejects it. The alternatives check in the issue body holds what the plugin covers and lacks. The plugin does not decide the project's fixture loop scope, so the proposal sets asyncio_default_fixture_loop_scope = "function" in [tool.pytest.ini_options] and runs the full suite to show that no async fixture needs a wider scope.

Key questions

  • Which value does asyncio_default_fixture_loop_scope take?: function, the scope that pytest-asyncio will default to, so the setting changes no fixture behavior now and no behavior after an upgrade. (best practice) [sources: pyproject.toml]
    • Chosen: function. It matches the future default of the plugin, so the option removes the warning and keeps the current fixture behavior.
    • Rejected: module or session. A wider scope changes the loop of each async fixture, and no fixture in the suite asks for it.
    • Rejected: leave the option unset. The warning stays on each worker, and a later release changes the fixture loop scope with no notice in the project config.
  • How does the plan show that no async fixture needs a loop scope wider than function?: Run the full suite with uv run devops ci test after the change. A fixture that needs a wider scope fails there, and it then declares its own scope on its fixture decorator. (best practice) [sources: pyproject.toml, tests/commands/test_review_pr_post.py]
    • Chosen: run the full suite. It exercises each async fixture under the new scope, and it is the same run that the required check does.
    • Rejected: read each async fixture by hand. A static read misses fixtures that a marker or a conditional selects, and it costs more than the suite run.
  • Should the warning go into filterwarnings instead of the ini option?: No. A filter hides the warning, and the unset option still changes the fixture loop scope in a later release. Set the option, as the plugin asks. (best practice) [sources: pyproject.toml]
    • Chosen: set the ini option. It answers what the warning asks, and it keeps the migration signal for a later release.
    • Rejected: add a filterwarnings ignore. It hides the warning and leaves the fixture loop scope to the default of the next release.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/ci
    status/new
    value/low
    effort/low
    on Nov 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p3-low
    on Nov 13, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The warning comes from pytest-asyncio itself, and that plugin owns the ini option asyncio_default_fixture_loop_scope, so setting it in [tool.pytest.ini_options] removes the warning for the whole project with no new tool. The project already depends on pytest-asyncio, and no ADR rejects it.

    The repository already uses this tool.

    Tool: pytest-dev/pytest-asyncio (https://github.com/pytest-dev/pytest-asyncio)

    • License: Apache-2.0
    • Last activity: 2026-11-15
    • Maintained: yes

    Covers:

    • Provides the asyncio_default_fixture_loop_scope pytest ini option that the deprecation warning asks for
    • Is the plugin that emits the warning and reads the project's asyncio_mode = "auto" setting
    • An explicit value in [tool.pytest.ini_options] silences the warning once per worker without code changes

    Lacks:

    • Does not decide the scope for the project: someone must confirm no async fixture needs a wider scope than function
    • Does not remove the warning by default; the option stays unset until the project sets it
    • Later releases change the default fixture loop scope, so the explicit value is still needed after upgrades

    Tools considered:

    Searches run:

    • PytestDeprecationWarning asyncio_default_fixture_loop_scope is unset fix pyproject.toml, results: 5
    • pytest-asyncio asyncio_default_fixture_loop_scope configuration option, results: 5
    • pytest-asyncio docs configuration asyncio default fixture loop scope function, results: 5
    • pytest-asyncio github repository pytest-dev pytest-asyncio, results: 5
    • "asyncio_default_fixture_loop_scope", results: 5
    • pytest-asyncio, results: 5
    • pytest-asyncio changelog deprecation warning default fixture loop scope removed, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 20, 2026
  6. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p3-lowscope/cisource/agentstatus/readytype/bugvalue/low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions