我使用 PyTest 在 Sanic 中运行以下测试,但我得到了
找不到夹具“循环”
错误,我按照make app 返回 Sanic app的链接中的教程进行操作。
import pytest
import json
from main import make_app
@pytest.yield_fixture
def app():
app = make_app()
yield app
@pytest.fixture
def test_cli(loop, app, test_client):
return loop.run_until_complete(test_client(app))
async def test_fixture_test_client_post(test_cli):
data = {
"urls" : [
"https://images.pexels.com/photos/789380/pexels-photo-789380.jpeg",
"https://images.pexels.com/photos/280204/pexels-photo-280204.jpeg"
]
}
response = await test_cli.post('/v1/images/upload',data=json.dumps(data))
assert response.status == 200