我如何使用doctest测试异步功能?

问题描述 投票:0回答:1

示例代码:

async def test():
  """
  >>> await test()
  hello world
  """
  print("hello world")

尝试用doctests运行此命令会导致SyntaxError: 'await' outside function

python-3.x python-asyncio doctest
1个回答
0
投票

Doctest在任何功能之外运行代码中的代码。您不能在异步函数外使用await表达式。

© www.soinside.com 2019 - 2024. All rights reserved.