Skip to content

fix: parametrize loop factory for sync tests using async fixtures - #1636

Closed
EnesKartal wants to merge 1 commit into
pytest-dev:mainfrom
EnesKartal:fix/loop-factory-sync-test-async-fixture
Closed

EnesKartal wants to merge 1 commit into
pytest-dev:mainfrom
EnesKartal:fix/loop-factory-sync-test-async-fixture

Conversation

@EnesKartal

Copy link
Copy Markdown

Summary

  • Update pytest_generate_tests() (pytest_asyncio/plugin.py) to also parametrize _asyncio_loop_factory for synchronous tests that depend on pytest-asyncio-managed async fixtures, using the outermost loop scope of those async fixtures.
  • Prevents _scoped_runner and shared async fixtures from being torn down prematurely when a sync test runs after an async test under pytest_asyncio_loop_factories.
  • Add regression test test_sync_test_with_shared_async_fixture_and_loop_factories in tests/test_loop_factory_parametrization.py.

Test Plan

  • .venv\Scripts\python.exe -m pytest tests/test_loop_factory_parametrization.py -q --basetemp=.pytest-tmp -> 41 passed.

Fixes #1501

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.04%. Comparing base (599fb32) to head (cc2824c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1636      +/-   ##
==========================================
+ Coverage   94.86%   95.04%   +0.18%     
==========================================
  Files           2        2              
  Lines         506      525      +19     
  Branches       60       64       +4     
==========================================
+ Hits          480      499      +19     
  Misses         21       21              
  Partials        5        5              

☔ 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.

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.

Loop factory parametrization tears down async fixtures used by sync tests

3 participants