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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiounittest-1.5.0.tar.gz.
File metadata
- Download URL: aiounittest-1.5.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c20ab00909419749061a4cb1a2755f034d10c1f6455adb1f03d7c16dedce711
|
|
| MD5 |
a0011254bc26271b84c3f22d8afa9223
|
|
| BLAKE2b-256 |
6f90f0d1ef74a0c022ac64b42d8a278c8f9cbdf2d5049a8f1e7707f4c5f80358
|
File details
Details for the file aiounittest-1.5.0-py3-none-any.whl.
File metadata
- Download URL: aiounittest-1.5.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30e709730e010c7daa1a0e3ce7398beebd2977d4dbf0a2875b8ed55830ab9d34
|
|
| MD5 |
3515ee3dd82b96a804cd20ca817b22a0
|
|
| BLAKE2b-256 |
20b65a02761969f8bf2c8263ce413c6253cb51a7224559c45608fa8f83e00f3a
|