Skip to content
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

Fix fixture ordering and event loop being set to None in fixture #684

Merged
merged 3 commits into from
Nov 26, 2023

Conversation

seifertm
Copy link
Contributor

Fixes a bug related to the ordering of the "event_loop" fixture in connection with parametrized tests.

The fixture evaluation order changed for parametrizations of the same test. The reason is probably the fact that event_loop was inserted at position 0 in the pytest fixture closure for the current test. Since the synchronization wrapper for async tests uses the currently installed event loop rather than an explicit reference as of commit 36b2269, we can drop the insertion of the event_loop fixture as the first fixture to be evaluated.

This patch also addresses an issue that caused RuntimeErrors when the event loop was set to None in a fixture that is requested by an async test. This can occur due to the use of asyncio.run, for example.

Closes #658

…op policy for the scope of the context.

Signed-off-by: Michael Seifert <[email protected]>
… in connection with parametrized tests.

The fixture evaluation order changed for parametrizations of the same test. The reason is probably the fact that `event_loop` was inserted at position 0 in the pytest fixture closure for the current test. Since the synchronization wrapper for async tests uses the currently installed event loop rather than an explicit reference as of commit 36b2269, we can drop the insertion of the event_loop fixture as the first fixture to be evaluated.

This patch also addresses an issue that caused RuntimeErrors when the event loop was set to None in a fixture that is requested by an async test. This can occur due to the use of asyncio.run, for example.

Signed-off-by: Michael Seifert <[email protected]>
@seifertm seifertm added this to the v0.23 milestone Nov 22, 2023
@seifertm seifertm enabled auto-merge November 26, 2023 08:17
@seifertm seifertm added this pull request to the merge queue Nov 26, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (810c9d7) 94.75% compared to head (b55b963) 94.79%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #684      +/-   ##
==========================================
+ Coverage   94.75%   94.79%   +0.03%     
==========================================
  Files           2        2              
  Lines         458      461       +3     
  Branches       93       95       +2     
==========================================
+ Hits          434      437       +3     
  Misses         15       15              
  Partials        9        9              

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

Merged via the queue into pytest-dev:main with commit fac9092 Nov 26, 2023
8 checks passed
@seifertm seifertm deleted the fixture-ordering branch November 26, 2023 08:20
@seifertm seifertm restored the fixture-ordering branch November 26, 2023 12:44
@seifertm seifertm deleted the fixture-ordering branch November 26, 2023 13:06
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.

RuntimeError: There is no current event loop in thread 'MainThread'.
2 participants