【发布时间】:2016-12-28 11:06:19
【问题描述】:
是否可以将 pytest 固定装置编写为龙卷风协程?例如,我想编写一个用于创建数据库的夹具,如下所示:
from tornado import gen
import pytest
@pytest.fixture
@gen.coroutine
def get_db_connection():
# set up
db_name = yield create_db()
connection = yield connect_to_db(db_name)
yield connection
# tear down
yield drop_db(db_name)
@pytest.mark.gen_test
def test_something(get_db_connection):
# some tests
很明显,这个fixture不能像预期的那样工作,因为它是作为一个函数调用的,而不是作为协程调用的。有办法解决吗?
【问题讨论】: