Test asyncio code more easily.
Project description
aiounittest
Info
This 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)
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 provide some additional tooling:
AsyncMockIterator to mock object for async for,
futurized to mock 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
aiounittest-1.3.0.tar.gz
(5.4 kB
view details)
File details
Details for the file aiounittest-1.3.0.tar.gz
.
File metadata
- Download URL: aiounittest-1.3.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e847482b85c2b01fa8c99ffc9606811257448899707b7c7ec06e0f11c019603f |
|
MD5 | 8d5d407b232afb981252ec9d45eb346e |
|
BLAKE2b-256 | 58d8dec59fa116f6402b634b63878ee69d95e4d9af1b80bd0ea2828f85fac3e9 |