-
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
Make it possible to avoid using the global loop #21
Conversation
I can't seem to reproduce the 3.4 test failure locally. |
Hi, On 17:23, Fri, Apr 29, 2016 Leifur Halldor Asgeirsson <
|
So here's the thing. When I said overriding the event loop would be the way to go, I actually tested it out first using the following code:
as you can see, the What I propose we do instead is move the logic of setting the produced event loop outside of the
|
Sorry about the delay getting back to you! I'm not sure I understand your proposal; I can see that the way I had tried overwriting the event_loop fixture may lead to problems, and these changes would certainly simplify that fixture. I'm trying to enforce that when I run my tests, my application code should never access the global loop. How would I do that with these changes? If a client developer were to call In my local conftest, I overwrote the event_loop fixture and set the global loop as None so that if the tests run any application code that tries to get the global loop, the test should fail with a RuntimeError. This approach wouldn't work if the pytest asyncio marker sets the result of the event_loop fixture as the global loop before running the test method. All my application code would run on the correct loop, but my tests wouldn't pick up on places where my application accesses the global loop. I did some googling and found that in the For example, maybe a marker |
Ah, I understand now. Let me dwell on it a little. Ideally we'd both have a simplified way of overriding the event loop, and a way of making get_event_loop throw errors. The asyncio_forbid_global_loop marker might not be a bad idea. |
How about this approach:
|
That would be perfect! |
I could write a possible implementation for that on Monday. |
Don't worry about it, I've already written it playing around. :) On Sun, May 8, 2016 at 11:55 PM Leifur Halldor Asgeirsson <
|
I'll merge this so you're in the contributors. I'll build on it in the next few days with the changes. Thanks for contributing! |
Hotfix: savepoints
I'm working on a project that aims not to depend on the implicit global loop; that is, if a client developer explicitly passes an event loop instance to classes and functions in this package, only that loop will be used.
Because many other packages, including
asyncio
itself, will get the default loop when not passed an instance explicitly, we would like to run our tests against a non-global loop instance to enforce this requirement.To that end, I tried overriding the
event_loop
fixture, but I found that the pytest-asyncio marker is implicitly retrieving the default event loop via the call toasyncio.async
. This proposed change simply passesevent_loop
explicitly toasyncio.async
.I wrote the corresponding test in its own module so that I could override the
event_loop
fixture and verify that asyncio marked test functions run correctly even if there is no default event loop set.