Skip to content
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

Support coroutines with async and await syntax #17

Merged
merged 2 commits into from Dec 18, 2015

Conversation

dirn
Copy link
Contributor

@dirn dirn commented Dec 17, 2015

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.

@Tinche
Copy link
Member

Tinche commented Dec 17, 2015

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.
@Tinche
Copy link
Member

Tinche commented Dec 18, 2015

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
@Tinche Tinche merged commit a2a8949 into pytest-dev:master Dec 18, 2015
@dirn
Copy link
Contributor Author

dirn commented Dec 18, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants