Test asyncio code more easily.
Project description
aiounittest
Info
The aiounittest is a helper library to ease of your pain (and boilerplate), when writing a test of the asynchronous code (asyncio
). You can test:
synchronous code (same as the
unittest.TestCase
)asynchronous code, it supports syntax with
async
/await
(Python 3.5+) andasyncio.coroutine
/yield from
(Python 3.4)
In the Python 3.8 (release note) and newer consider to use the unittest.IsolatedAsyncioTestCase. Builtin unittest
module is now asyncio-featured.
Installation
Use pip:
pip install aiounittest
Usage
It’s as simple as use of unittest.TestCase
. Full docs at http://aiounittest.readthedocs.io.
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)
Library provides some additional tooling:
AsyncMockIterator mocking for async for,
futurized mock for coroutines.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aiounittest-1.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11634918fbbf09b954d97c74d857835750d025d1cafb675391d0099b8d83665a |
|
MD5 | ef1a69c0b3620e2473dd9656ebb73308 |
|
BLAKE2b-256 | 2e44df1984e64e06ba42174835b10d7184ce3e342a8038c6d5a256b4fa739b78 |