我的问题:我需要一种简单的方法来将测试方法标记为协程。(在其他原因中,我希望最小化asyncio版本和原始代码之间的差异。)
下面的代码可以工作-除了test_one,它被忽略了。
我已经研究了pytest和pytest-asyncio的内部结构,虽然我(基本上)理解了它是如何将自身连接起来以增强简单的测试功能的,但我不明白如何使用单元测试方法来做同样的事情。
那么我该怎么做呢?
import unittest
import asyncio
import pytest
class TestSimple(unittest.TestCase):
@pytest.mark.asyncio
def test_one(self):
print("One")
yield from asyncio.sleep(0.2)
print("Two")
def test_two(self):
print("Three")
def test_three():
print("Four")
@pytest.mark.asyncio
def test_four():
print("Five")
yield from asyncio.sleep(0.2)
print("Six")发布于 2015-11-11 22:52:27
将unittest风格与原生pytest相交错是不可能的。
如果你需要编写单元测试风格的测试,你可以使用装饰器,比如aioredis。
https://stackoverflow.com/questions/33625850
复制相似问题