-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Pytest async fixtures #2226
Pytest async fixtures #2226
Conversation
ed85123
to
aec50d9
Compare
Codecov Report
@@ Coverage Diff @@
## master #2226 +/- ##
=========================================
+ Coverage 97.29% 97.3% +0.01%
=========================================
Files 39 39
Lines 8016 8051 +35
Branches 1388 1395 +7
=========================================
+ Hits 7799 7834 +35
Misses 94 94
Partials 123 123
Continue to review full report at Codecov.
|
dc2766d
to
2ff86fd
Compare
2ff86fd
to
414e55e
Compare
Your PR is awesome! Would you add add couple words to http://aiohttp.readthedocs.io/en/stable/testing.html#pytest for introducing the feature? |
Yes I'll had some documentation soon. I wanted to have some feedback first, but now we're good :) . |
Just a note based on a glance at this (so apologies if I'm missing some important difference), but this seems like reinventing pytest-asyncio, which provides a more robust feature set. aiohttp already has deps on some other pytest plugins, and this seems like a natural one to add to that set. |
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.
LGTM
Thanks! |
Despite my initial scepticism, this looks like it should be really useful. Thanks a @k4nar, you'll save me writing |
@asvetlov @k4nar I guess my comment went under the radar, as there was no response. I'll mention it just this one more time in case it was just missed: I haven't had to write |
pytest-asyncio is not fully compatible with pytest-aiohttp (while last pytest-asyncio commits has smoothed some corners). The crucial difference is disabling global event loop by default in pytest-aiohttp. After |
What do these changes do?
With this PR, pytest fixtures can be coroutines. For example, in order to create a client, you can use:
This is not a killer feature as you could already do the same thing using
loop.run_until_complete
, but I find it more idiomatic.The main gotcha is that in order for an async fixture to work, it must use the
loop
fixture, or be called in a test using it. The previous example works becausetest_client
uses theloop
fixture.I don't think this is a big issue because I can't think of any case where one would want an asynchronous fixture without using the loop.
Are there changes in behavior for the user?
None.
Related issue number
#2223
Checklist
CONTRIBUTORS.txt
changes
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.