常用pytest,有需要可以安装pytest-asyncio插件(跟普通的pytest差不多,多了一个异步机制)。
pytest应用的话,新建一个tests文件夹,构建相关测试文件即可,测试文件命名形式如:test_name.py。
具体测试方法如下方实例:
#pytest实例
import pytest
def A():
total=1+2
return total
def B():
res=A()
assert str(type(res)) == "<class 'int'>"
#也可以这样写
import pytest
@pytest.mark.asyncio
async def A():
total=1+2
return total
@pytest.mark.asyncio
async def B():
res=A()
assert str(type(res)) == "<class 'int'>"