Skip to content

Limit event_loop_policy parametrization to async tests#1491

Open
lin-hongkuan wants to merge 1 commit into
pytest-dev:mainfrom
lin-hongkuan:codex/limit-event-loop-policy-autouse
Open

Limit event_loop_policy parametrization to async tests#1491
lin-hongkuan wants to merge 1 commit into
pytest-dev:mainfrom
lin-hongkuan:codex/limit-event-loop-policy-autouse

Conversation

@lin-hongkuan

Copy link
Copy Markdown

Summary

  • stop parametrized event_loop_policy autouse fixture overrides from applying to synchronous tests that do not request the fixture
  • keep explicit synchronous uses of event_loop_policy intact, including direct fixture arguments and usefixtures
  • add a regression test covering one async test and one sync test with a parametrized policy fixture

Fixes #796

Tests

  • python -m pytest tests\markers\test_event_loop_policy.py -q -p no:twisted
  • python -m pytest tests\markers\test_function_scope.py::test_asyncio_mark_respects_parametrized_loop_policies tests\markers\test_function_scope.py::test_event_loop_policy_fixture_override_emits_deprecation_warning tests\markers\test_function_scope.py::test_default_event_loop_policy_fixture_does_not_warn -q -p no:twisted
  • python -m pytest tests\markers -q -p no:twisted
  • python -m ruff check pytest_asyncio\plugin.py tests\markers\test_event_loop_policy.py
  • python -m ruff format --check pytest_asyncio\plugin.py tests\markers\test_event_loop_policy.py
  • git diff --check

Note: I used -p no:twisted locally because this environment has an unrelated global pytest-twisted plugin installed, and it interferes with pytester subprocess runs. The pytest-asyncio tests themselves pass with that unrelated plugin disabled.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.30%. Comparing base (c5221cf) to head (3080bc3).

Files with missing lines Patch % Lines
pytest_asyncio/plugin.py 46.15% 3 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1491      +/-   ##
==========================================
- Coverage   94.50%   93.30%   -1.21%     
==========================================
  Files           2        2              
  Lines         510      523      +13     
  Branches       62       66       +4     
==========================================
+ Hits          482      488       +6     
- Misses         22       25       +3     
- Partials        6       10       +4     

☔ View full report in Codecov by Harness.
📢 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.

@tjkuson tjkuson left a comment

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.

Noting #796 (comment), we should probably be wary of implementing pytest hacks in order to resolve an issue with a deprecated feature.

Comment thread pytest_asyncio/plugin.py
for marker in metafunc.definition.iter_markers(name="usefixtures")
):
return
if fixture_name in metafunc.fixturenames:

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 breaks valid usage for the same reason described here #1454

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.

Parametrizing event_loop_policy parametrizes all tests

3 participants