1
是否有可能將pytest fixtures編寫爲龍捲風協程?例如,我想寫一個夾具用於創建數據庫,就像這樣:如何使用協程作爲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
顯然,正如所料,因爲它是作爲函數調用,而不是協程在該項賽事中不起作用。有沒有辦法解決它?