-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5071 Use one event loop for all asyncio tests #2086
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e455fa6
Use one loop for asyncio test suite
ShaneHarvey eb75d77
PYTHON-5071 Fix AsyncPyMongoTestCase implementation
ShaneHarvey c08fceb
PYTHON-5071 Fix setup
ShaneHarvey 2ed7c60
PYTHON-5071 Ignore get_event_loop deprecation
ShaneHarvey 87cbd36
PYTHON-5071 Stop reinitializing client_context
ShaneHarvey 148482c
PYTHON-5071 Bind to pytest's event loop so that it gets cleaned up at…
ShaneHarvey 3a2d844
PYTHON-5071 Go back to package scope
ShaneHarvey b9fcba7
PYTHON-5071 Cleanup
ShaneHarvey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be
get_loop
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is the correct method to call within an async function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I think we still have a loop mismatch here, although I might be misunderstanding: this will use the loop pytest creates for our package-scoped
test_setup_and_teardown
fixture. Then, our first async testcase will create its own separate loop that will be used for each test. So ourasync_client_context
will be on one pytest-managed loop, and all of our test cases will be on one self-managed loop created byget_loop
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our
pyproject.toml
also sets the default loop_scope to besession
instead ofpackage
FYI.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either one is fine because get_loop calls get_running_loop first but I updated to use get_loop to be more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempting to use "package" in pyproject.toml results in this error:
"session" seems to be the right thing for what we want there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened pytest-dev/pytest-asyncio#1052 about that exact error, it persists even if you explicitly mark a fixture as
package
.With any pytest-asyncio scope, we'll still have two separate loops. That doesn't seem to be causing test failures, but it's something to be aware of for future debugging 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I subscribed to that issue. However I did verify that the current code only ever uses 1 loop for the whole async test suite. Printing the loop that pytest-asyncio creates shows this:
event_loop_fixture_id='_session_event_loop'
which means theasyncio_default_fixture_loop_scope="session"
in pyproject is behaving as expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean that
get_loop
is picking up and using pytest's_session_event_loop
? Or that that loop is separate from the loop the tests use thatget_loop
creates?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one.