What? Why? Next?¶
Why Not?¶
In the Python 3.8 (release note) and newer consider to use the unittest.IsolatedAsyncioTestCase. Builtin unittest
module is now asyncio-featured.
What?¶
This module is a set of helpers to write simple and clean test for asyncio-based code.
Why?¶
Actually this is not nothing new, it just wraps current test approach in the handy utils. There are couple libraries that try to solve this problem. This one:
- integrates nicely with standard
unittest
library, - is as simple as possible, without a bunch of stuff that is straithforward with unittest (eg re-inveting
assertRaises
with assertAsyncRaises), - supports both Python 3.5+ syntax and Python 3.4,
- it’s well-documented (I think)
Among the others similar modules the best known is an extension pytest-asyncio. It provides couple extra features, but it cannot be used with unittest.TestCase (it does not support fixture injection).
Further reading:
Next?¶
- introduce
AsyncMock
, … Probably not, theunitest.mock.Mock
withfuturized
is pretty simple. - it would be great if unittest could support async test > python-ideas