[Python-ideas] async unittest.TestCase

David Shawley daveshawley at gmail.com
Wed Oct 10 07:10:55 EDT 2018


Hi everyone and good morning to some of you,

Since asyncio and the async/await syntax are both part of Python, I think
that we should extend TestCase to support it.  The simplest solution that
I can think of is to create unittest.AsyncTestCase sub-class with the
following extensions:

 - create a new event loop and install it in AsyncTestCase.run
 - make it possible for setUp, tearDown, and test methods to be async
   by calling asyncio.iscoroutinefunction

I wrote my own in a local test before noticing that Martin Richard had
already written and published asynctest [1].  Since then I found the
following projects as well:

 - https://github.com/kwarunek/aiounittest <https://github.com/kwarunek/aiounittest>
 - https://github.com/pytest-dev/pytest-asyncio <https://github.com/pytest-dev/pytest-asyncio>

I think that the community as a whole would benefit from basic support in
unittest for async/await test "user methods".  I am personally fond of the
approach of extending unittest.TestCase in asynctest [2] over some of the
other approaches.

Is this something that we want in our Standard Library?

- dave
--
[1]: https://github.com/Martiusweb/asynctest <https://github.com/Martiusweb/asynctest>
[2]: https://github.com/Martiusweb/asynctest/blob/master/asynctest/case.py <https://github.com/Martiusweb/asynctest/blob/master/asynctest/case.py>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181010/eb44cf6e/attachment.html>


More information about the Python-ideas mailing list