Skip to content

Fix: Add validation for asyncio_default_fixture_loop_scope #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pankaj-bind
Copy link

This PR addresses an issue where the asyncio_default_fixture_loop_scope configuration option in pytest.ini was not being validated. This could lead to misconfigurations and unexpected behavior without providing any feedback to the user.

This change introduces a validation check in pytest_asyncio/plugin.py to ensure that the provided scope is one of the valid options (function, class, module, package, or session). If an invalid scope is provided, a pytest.UsageError is raised with a descriptive error message.

Additionally, a new test case has been added to tests/test_fixture_loop_scopes.py to verify that an invalid scope configuration correctly raises an error.

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.67%. Comparing base (4fbe1e0) to head (4bd8a3b).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
pytest_asyncio/plugin.py 72.72% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1189      +/-   ##
==========================================
- Coverage   88.88%   88.67%   -0.22%     
==========================================
  Files           2        2              
  Lines         405      415      +10     
  Branches       44       46       +2     
==========================================
+ Hits          360      368       +8     
- Misses         35       36       +1     
- Partials       10       11       +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
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.

This is a great idea! . It will give better error messages in case the user has a typo in their configuration. The code and test look solid. The only thing that's left is notifying the users about this addition in the changelog.

To add a changelog entry, you can simply add a file (aka news fragment) to changelog.d/ stating that incorrect configuration values for default_fixture_loop_scope and default_test_loop_scope now give a better error message. The news fragment should point to the underlying issue or, in this case, the PR and should have the category added. That means the complete file path for the news item is changelog.d/1189.added.rst.

I'd also appreciate if you could squash the commits in this PR (just this once), so we don't have the fixup commits from pre-commit CI in the Git history.

fix linters issue

added changelog entry
@pankaj-bind pankaj-bind force-pushed the validate-fixture-loop-scope branch from f583e73 to 4437281 Compare August 18, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants