asynctest
asynctest copied to clipboard
Add tests for asynchronous generators
Asynchronous generators are defined by PEP 525 and supported since Python 3.6
Unfortunately the syntax change (yielding from a coroutine) is not backward compatible, previous versions of Python will raise a SyntaxError
.
The test suite should be extended to allow version-specific tests. Since the error happens during interpretation, runtime checks are not sufficient. Therefore discovery mechanics should exclude the test module before an attempt to import it is made.
There's already a solution for python 3.4 and async/await:
if sys.version_info >= (3, 5):
from . import test_case_await as _using_await
else:
_using_await = None
https://github.com/Martiusweb/asynctest/blob/master/test/test_case.py#L16
It works because tests are executed with
python -m unittest tests
which loads the "tests" package, importing the modules (except the one using async/await). These version-specific modules are only imported if the runtime can parse them.
Do you have a better solution in mind?
I'm using the py.test runner, yet to try this approach.