【发布时间】:2018-01-25 22:23:53
【问题描述】:
我正在尝试为 aiohttp 应用程序编写测试。我正在使用 pytest-aiohttp 插件。我的目的是在第一次测试执行之前初始化并运行一次应用程序,并在所有测试完成后拆除。像'loop'、'test_client'这样的pytest-aiohttp 夹具非常有用,但它们有scope='function',这意味着我不能从我自己的带有scope='session'的夹具中使用它们。有没有办法解决这个问题?如果不是,那么在不使用内置固定装置的情况下实现我的目标的正确方法是什么? 我的代码如下(conftest.py)
@pytest.fixture()
def client(test_client, loop):
app = init(loop)
return loop.run_until_complete(test_client(app))
我的测试然后使用这个
class TestGetAlerts:
async def test_get_login_url(self, client):
resp = await client.get('/api/get_login_url')
assert resp.status == 200
所以我的夹具“客户端”为每个测试运行,这是我想要避免的
【问题讨论】:
标签: python pytest fixtures aiohttp