Skip to content

Set default asyncio fixture loop scope to function#1444

Open
SahilArchitect wants to merge 5 commits into
pytest-dev:mainfrom
SahilArchitect:fix-924-default-fixture-loop-scope
Open

Set default asyncio fixture loop scope to function#1444
SahilArchitect wants to merge 5 commits into
pytest-dev:mainfrom
SahilArchitect:fix-924-default-fixture-loop-scope

Conversation

@SahilArchitect
Copy link
Copy Markdown

Closes #924.

Summary

Sets the default value of asyncio_default_fixture_loop_scope to function and removes the deprecated unset
fallback/warning path.

This intentionally only changes the default for async fixture loop scope. It does not change async test loop scope
behavior, custom event_loop fixture deprecations, pytest warning filtering order, or quoted pytest.ini value
parsing.

Changes

  • Default unset asyncio_default_fixture_loop_scope to function
  • Remove the old fallback to fixture caching scope
  • Update docs and changelog wording
  • Add regression coverage for the unset/default behavior

Tests

  • python -m pytest tests/test_fixture_loop_scopes.py
  • python -m pytest tests/test_asyncio_fixture.py tests/modes/test_auto_mode.py tests/modes/test_strict_mode.py

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.87%. Comparing base (74a5557) to head (6b37a20).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1444      +/-   ##
==========================================
+ Coverage   94.50%   94.87%   +0.36%     
==========================================
  Files           2        2              
  Lines         510      507       -3     
  Branches       62       61       -1     
==========================================
- Hits          482      481       -1     
+ Misses         22       21       -1     
+ Partials        6        5       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@seifertm seifertm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the initiative, @SahilArchitect .

This is a breaking change that requires a major version bump. The next version will be v1.4.0, so I won't merge the PR just yet. In the meantime, could you have a look at my comments?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The news fragment describes a change of a warning message. Your change is unrelated to this news fragment and will be included in a different release. Please remove any modifications to this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the migration guide for users looking to upgrade from an older version of pytest-asyncio. This patch doesn't change anything in the upgrade path. Please remove any modifications to this file.

Comment thread docs/how-to-guides/migrate_from_0_23.rst
Comment thread tests/test_fixture_loop_scopes.py
@seifertm seifertm added this to the v2.0 milestone May 15, 2026
@SahilArchitect
Copy link
Copy Markdown
Author

Thanks for the review. I pushed a follow-up commit now.

What I changed:

  • restored changelog.d/1298.changed.rst, since that was for the older warning-message change
  • restored both migration guide files, since this PR does not need to change those upgrade docs
  • updated the regression test so it now actually proves the unset default is using function

For the test: I changed it to use a scope="module" async fixture with no explicit loop_scope. With the old behavior, that would fall back to the module fixture scope and pass. With the new behavior, it tries to use _function_scoped_runner, so we get the expected ScopeMismatch. That makes the behavior difference visible in the test.

I also reran:

.venv/bin/python -m pytest tests/test_fixture_loop_scopes.py -q
.venv/bin/python -m pytest tests/test_asyncio_fixture.py tests/modes/test_auto_mode.py tests/modes/test_strict_mode.py -q

Both passed.

@SahilArchitect SahilArchitect requested a review from seifertm May 15, 2026 11:39
Comment thread tests/test_fixture_loop_scopes.py
@SahilArchitect SahilArchitect requested a review from seifertm May 15, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finish deprecation of unset asyncio_default_fixture_loop_scope

3 participants