跳转到主要内容

更轻松地进行asyncio代码测试。

项目描述

aiounittest

image0 image1

信息

The aiounittest 是一个辅助库,可减轻您编写异步代码(asyncio)测试时的痛苦(和样板代码)。您可以测试

  • 同步代码(与 unittest.TestCase 相同)

  • 异步代码,支持 async/await(Python 3.5+)和 asyncio.coroutine/yield from(Python 3.4)的语法

在 Python 3.8(《发布说明》)及更高版本中,建议使用 unittest.IsolatedAsyncioTestCase。内置的 unittest 模块现在具有 asyncio 功能。

安装

使用pip

pip install aiounittest

用法

使用方法与 unittest.TestCase 相同。完整文档请参阅 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)

库提供了一些额外的工具

许可

MIT

项目详细信息


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分布

aiounittest-1.4.2.tar.gz (5.8 kB 查看哈希值)

上传时间 源代码

构建分布

aiounittest-1.4.2-py3-none-any.whl (7.0 kB 查看哈希值)

上传时间 Python 3

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误记录StatusPageStatusPage状态页面