-
Notifications
You must be signed in to change notification settings - Fork 158
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
Release 0.14 breaks tests that rely on a specific event_loop_policy #168
Comments
@wouterdb will dig into this over the weekend! |
Thx!
…On Sat, Jun 27, 2020, 03:45 Tin Tvrtković ***@***.***> wrote:
@wouterdb <https://github.com/wouterdb> will dig into this over the
weekend!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#168 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANUSXUE36Y2RYD7VUFIFDDRYVFKJANCNFSM4OIKB57Q>
.
|
Thanks also for your kind feedback. I did V0.14 changes you are referring, and I was not fully aware of your user case. With this in mind and after some debugging, I see no problem to roll back some of V0.14 changes: @Tinche With these changes all our unitary tests keep passing. |
Yeah, it would be great if we could treat the loop policy in the plugin as read-only (i.e. use it for generating event loops but let users override it). Another use case I imagine is very common is testing with UVLoop. |
@alblasco I've done some work on the 'policies' branch, but I still have trouble making all the tests pass. The first test in a package still uses the wrong event loop for some reason. |
To take into account user case that sets a specific event loop policy before runnins pytest asyncio tests: - Rollover changes in V0.14 (that clears event loop policy in pytest_fixture_post_finalizer) - include a new unit test that checks if policy has been changed (fails with V0.14 and pass with this PR).
@wouterdb I'm doing some work to support this use case over at #174. Due to a lot of users using the plugin in a multitude of ways, it's not super trivial to fix. The fix I'm proposing for now is to treat fixtures named |
This would work for us. (It would actually be a lot cleaner than what we do now.) Thank you for you fast response. |
I'm afraid I don't follow all the discussion, but this sentence seems troublesome. In our case the library itself is setting a policy (because we utilize tornado which cannot use the default proactor on windows). I maintain that we should not have to do or set anything at all in our tests in order to have the library-configured policy be respected as-is (otherwise, we fail to be able to test that the library itself is configuring the policy, as it must do). |
To us, it would be good if pytest doesn't touch the policy (as it did before), but if it does reset it, I would prefer to be able to control what it is reset to. The problem for us is that pytest now resets the event_loop_policy after every test.
The reverse side of this is that we have many unit test that don't configure the policy themselves (the code that configures the policy is out-of-scope for that test) so we need to be able to define a fixture that sets the policy before any of these test are executed. Current work arounddef patch_policy():
# work around for https://github.com/pytest-dev/pytest-asyncio/issues/168
oldloop = asyncio.get_event_loop_policy()
if not isinstance(oldloop, AnyThreadEventLoopPolicy):
newloop = AnyThreadEventLoopPolicy()
# transfer existing eventloop to the new policy
newloop.set_event_loop(oldloop.get_event_loop())
asyncio.set_event_loop_policy(newloop) |
Is this issue still active? Another symptom of this issue is subprocess no longer working, but perhaps that is because this bug triggers/interacts with #98 or sideways with #114.
|
FWIW we still pin to pytest-asyncio 0.12.0 but only for Python 3.8+ it seems. The pin was removed for earlier Python versions and awhile back and things seem to be working. I'm not sure if things would work now if the pin was removed on the later python versions, will have to try when time permits. |
I worked on this a little but abandoned it, can't remember why now since it's been a while. If you override the |
Problem
We have many testcases that rely on
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
We set the event loop policy in the conftest.py, such that it is set before any tests start.
Since 0.14 these testcases produce errors
Root cause
The change here: https://github.com/pytest-dev/pytest-asyncio/pull/164/files#diff-4d85e8313d8e67cb777137411a11ac86R80
Resets the event loop policy after the first test, breaking all the next tests.
The text was updated successfully, but these errors were encountered: