我有考试。它将获取请求发送到URL列表,并检查响应是否不是500。
@pytest.mark.asyncio
@pytest.mark.parametrize('url_test_list', get_all_url_list(HOST_FOR_TEST))
async def test_check_status_urls(self, url_test_list):
returned_status = await get(url_test_list)
assert returned_status < 500
这是我的“获取”功能
async def get(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
response_status = response.status
return response_status
它可以工作,但是速度很慢。完成大约需要3分钟。
但是,当我在不使用@parametrize的情况下使用此测试并且我的“ get”函数使用url_list时,它将运行约1分钟。我的第二种情况的代码:
@pytest.mark.asyncio
async def test_check_status_urls(self):
url_list = make_url_list()
returned_status = await get(url_list)
assert all(returned_status) > 500
async def get(urls):
good_list = []
async with aiohttp.ClientSession() as session:
for url in urls:
async with session.get(url) as response:
response_status = response.status
good_list.append(response_status)
return good_list
我希望在这里能两全其美。有什么方法可以使测试快速运行,又可以作为单个单元运行?