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.
pip install aiounittestVerified import paths — ran on the pinned version, not inferred.
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.
Migrate tests to inherit from `unittest.IsolatedAsyncioTestCase` and adjust any `aiounittest`-specific helpers as needed.
Initialize `asyncio` objects within the `async def` test methods themselves, or override `get_event_loop` if you need to manage the loop lifecycle more granularly, ensuring objects are created with the test-specific loop.
Rewrite coroutines using `async def` and `await` syntax.
Ensure that any `asyncio` objects required by your test are created within the `async def` test method itself, or use `self.loop` (if overridden `get_event_loop`) to explicitly get the test's event loop.
Prepend `await` to the call of any coroutine that you intend to execute, e.g., `await my_async_function()`.
When mocking asynchronous functions, use `unittest.mock.AsyncMock` instead of `MagicMock`. For example: `with patch('module.async_func', new_callable=AsyncMock) as mock_func:` or use `aiounittest.futurized`.No dependency data recorded yet.