【发布时间】:2021-09-25 07:39:46
【问题描述】:
当你编写一个普通函数时,通常你可以通过在 Python 控制台中运行它来对其进行单元测试。假设您的带有一个字符串 arg 的“myprint”位于module.py,
def myprint(s):
print("\ "+str(s))
只需cd 包含module.py 的目录并输入python3 并输入这些:
from module import *
myprint("a test")
但如果“myprint”是用async def 定义的,这种方式会失败并出现类似的错误
TypeError: 'coroutine' object is not callable
测试异步函数的正确方法是什么?
【问题讨论】:
-
鉴于this highly-rated and well-answered question 的存在,很难看出这个自我回答的问题给社区带来了什么价值——尽管我猜你对
async关键字的使用让它有些不同?跨度>
标签: python-asyncio