-
Notifications
You must be signed in to change notification settings - Fork 159
Weird interaction with pytest-mock: not requesting event_loop fixture leads to errors #818
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
Comments
This avoids conflict between the event loop and mocker fixtures. Without this fix, the event loop fixture tries to create a new event loop with a modified socket class, causing failure. pytest-dev/pytest-asyncio#818 This also completes "How to migrate from pytest-asyncio v0.21" in pytest-asyncio's docs.
The |
This bug manifests when not using the event_loop fixture, so it being removed only exacerbates the issue. From what I can see, the problem here is that the scope of the event loop intersects with mocker: after the mocker patches The workaround I used is to not use the To properly fix this in pytest-asyncio, it's probably necessary to ensure the lifecycle of the event loop fully encompass everything inside the test function including fixtures. |
@twisteroidambassador Thanks for the clarification!
We'd like to do that, as it would solve other issues like #112, but it's not part of the v1.0 release. I'm reopening the issue :) |
Consider the two test cases below:
The top one reports
ERROR at teardown of test_mocksocket_mocker
. The bottom one does not report any error. The only difference between them is that the bottom one requests theevent_loop
fixture.The error message is quite long. It seems to be caused by MockSocket still being active when
_provide_clean_event_loop()
is called, and the new event loop failing at initialization.Also, if the test case calls
unittest.mock.patch
instead ofmocker.patch
, then there is no error.Attached is the test file, full console output, and package versions. This is running on Windows 10.
pytest-asyncio-mock.zip
The text was updated successfully, but these errors were encountered: