aiounittest

1.5.0 · active · verified Thu Apr 16

aiounittest is a helper library designed to simplify testing asynchronous Python code built with `asyncio`. It extends `unittest.TestCase` to support `async`/`await` syntax (Python 3.5+) and `asyncio.coroutine`/`yield from` (Python 3.4). The library is actively maintained, with its latest version being 1.5.0, released in March 2025.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `aiounittest.AsyncTestCase` to write asynchronous tests. Your async test methods should be `async def` and use `await` where necessary. Synchronous test methods can coexist within the same class.

import asyncio
import aiounittest
import unittest

async def async_add(x, y, delay=0.01):
    await asyncio.sleep(delay)
    return x + y

class MyAsyncTest(aiounittest.AsyncTestCase):
    async def test_async_addition(self):
        result = await async_add(10, 20)
        self.assertEqual(result, 30)

    def test_sync_method(self):
        self.assertTrue(True)

# To run the tests (usually handled by test runners like `pytest` or `unittest` CLI)
if __name__ == '__main__':
    unittest.main()

view raw JSON →