Support coroutines with async and await syntax#17
Merged
Conversation
Member
|
Thanks for your contribution and working to make pytest-asyncio better! I'll do my best to take a look at this tomorrow and merge it in. |
PEP 492 added support for defining coroutines using `async def` rather than having to decorate the function with `@asyncio.coroutine`. The new `_is_coroutine` function will match any coroutines created with the decorator using `inspect.isgeneratorfunction` as well as those created through the async and await syntax using `asyncio.iscoroutinefunction`. The tests for this need to be added in an unconventional way. `async` and `await` cause syntax errors in versions of Python prior to 3.5. Rather than causing the tests for 3.3 and 3.4 to fail, the tests are being defined as a string and then compiled and executed into the module. If a time ever comes that this library no longer supports versions prior to 3.5, this new module can be removed entirely.
Member
|
Alright, I think this looks good. There's a better way of handling files with 3.5 only syntax: customize the test collector a little. I have this done and will apply a small commit on top of your work. After that, I'll update the README, change the examples to mainly use the new async/await syntax, bump the version up and do a release! Thanks for your work! Do you have a Twitter handle for me to mention you when I announce the release? |
Tinche
added a commit
that referenced
this pull request
Dec 18, 2015
Support coroutines with async and await syntax
Contributor
Author
|
I was looking for a better way to do it but couldn't seem to get the collector to work right. I'm glad you know how to do that. I'm @dirn on Twitter. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PEP 492 added support for defining coroutines using
async defratherthan having to decorate the function with
@asyncio.coroutine. The new_is_coroutinefunction will match any coroutines created with thedecorator using
inspect.isgeneratorfunctionas well as those createdthrough the async and await syntax using
asyncio.iscoroutinefunction.The tests for this need to be added in an unconventional way.
asyncand
awaitcause syntax errors in versions of Python prior to 3.5.Rather than causing the tests for 3.3 and 3.4 to fail, the tests are
being defined as a string and then compiled and executed into the
module. If a time ever comes that this library no longer supports
versions prior to 3.5, this new module can be removed entirely.