-
Notifications
You must be signed in to change notification settings - Fork 159
Require explicit marks for async fixtures #124
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
See also #61 |
Would it not be possible for the plugin to only act on fixtures if the requesting test is marked with |
A user just asked for support because they couldn't get pytest-trio working, and it turned out to be because they had a copy of pytest-asyncio installed as well. Their reproducer had an async fixture in it, so I'm pretty sure that this issue is the cause. https://gitter.im/python-trio/general?at=5d005d341edaa30adf0746fd |
I just had a quick go at fixing this, by adding the following code to the top of pytest-asyncio's if 'asyncio' not in request.keywords:
yield
return The idea being that pytest-asyncio would only apply its special handling to fixtures if they're being requested by an asyncio test. This seems like the simplest hack that would fix most of the surprising crashes. It almost works – if 'asyncio' not in request.keywords and 'asyncio' not in request._parent_request.keywords:
yield
return but that requires poking around in one of pytest's private APIs. CC: @RonnyPfannschmidt @nicoddemus – Any suggestions? |
We've had to divide our test suite up into separate runs because of this issue. It would be very nice to be able to run them side-by-side. I've opened #125 with an approach similar to how |
@pipermerriam Oh cool, I hadn't seen that! It might make sense to add in some sniffing logic like in my comment above? The nice thing about that is that in many cases it's backwards-compatible without users having to do anything, AND ALSO it fixes the pytest-trio breakage without users having to do anything. Without this kind of heuristic, then I think one case or the other requires user intervention. |
👍 I'll look into how I can combine the two to make for a better user experience. My goal was to set things out on a path that pointed in a direction where both play nicely by default but eventually having that mechanism be via an explicit fixture mark so that there's as little implicit inference as possible. |
I don't have a whole lot of time to dedicate to this, but I'd be happy to defer to @njsmith or @nicoddemus for any solutions and merge them in :) |
@njsmith this is easier in more modern pytest (3.6+ IIRC): asyncio_marks = list(request.node.iter_markers('asyncio'))
if not asyncio_marks:
yield
return This also covers your other example using |
Here's another user who got bit by this: python-trio/pytest-trio#85 |
This issue caught me recently as well — relevant discussions in agronholm/anyio#74 and agronholm/anyio#75 (comment). If #125 needs a helping hand I’d be happy to provide some @pipermerriam. :) |
@florimondmanca I'm getting burnt by this issue again so had a go at fixing the conflicts in #125 but didn't get very far |
pytest-asyncio
interprets allasync def
based fixtures as things that should be run by theasyncio
event loop. This appears to make it impossible for a test suite to have side-by-side tests for both libraries.This results in:
The text was updated successfully, but these errors were encountered: