Aiounittest
lastmod 2026-11-10created 2021-02-232 edits
aiounittest is a small library that lets you test asyncio-based code with Python's standard unittest. If you inherit from AsyncTestCase, test methods written with async def are automatically run inside an event loop, and ordinary synchronous tests can be mixed into the same class. It also provides an async_test decorator that turns a coroutine into something like a synchronous function.
Test python asyncio-based code with ease.
Usage
import asyncio
import aiounittest
async def add(x, y):
await asyncio.sleep(0.1)
return x + y
class MyTest(aiounittest.AsyncTestCase):
async def test_async_add(self):
ret = await add(5, 6)
self.assertEqual(ret, 11)
# or 3.4 way
@asyncio.coroutine
def test_sleep(self):
ret = yield from add(5, 6)
self.assertEqual(ret, 11)
# some regular test code
def test_something(self):
self.assertTrue(true)