【发布时间】:2015-11-10 08:40:45
【问题描述】:
我的问题:我需要一种简单的方法将测试方法标记为协程。 (除其他原因外,我想尽量减少 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")
【问题讨论】:
标签: python python-3.x pytest python-asyncio