我尝试使用pytest测试异步Python函数。我的测试是通过警告,当它应该失败的时候。在
这是我的测试:
import asynctest
import pytest
from Foo.bar import posts
@pytest.mark.asyncio
async def test_get_post_exists():
returned_post = await posts.get_post('0')
assert returned_post.id == 0
assert returned_post.text == 'Text for the post body.'
assert True == False
它传递以下消息:
^{pr2}$
下面是使用
pytest
和pytest-asyncio
的工作演示:Foo/bar/posts.py
:
^{pr2}$test_post_helpers.py
:单元测试结果:
assert True == False
因为断言如您所愿失败。在源代码:https://github.com/mrdulin/python-codelab/tree/master/src/stackoverflow/49350821
相关问题 更多 >
编程相关推荐