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
File details
Details for the file aiounittest-1.4.1.tar.gz
.
File metadata
- Download URL: aiounittest-1.4.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf51a4a430d28b1a527abb0bea1465a3a36a2bbca13bf9b84e749985b4c5a788 |
|
MD5 | 4c879d6c5003e88dd131ec62f4167e85 |
|
BLAKE2b-256 | 0099e18101dd69de0c1e8e4b24498bcdef601f9fb463fcb6e9ef907ff06f5501 |
File details
Details for the file aiounittest-1.4.1-py3-none-any.whl
.
File metadata
- Download URL: aiounittest-1.4.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c41ea2ae679ea426d0666b5e5c338119b999a9ba5c13ec08ab27f025147ee372 |
|
MD5 | 179483903e787666e4e48ed2f0ec8aa5 |
|
BLAKE2b-256 | 1176d23e6d049aed61ff716b34ffe6c0f64b3e50b3cd3bfaab384c9122107ad6 |