问题:为了提升用例执行速度,使用parallel插件进行并发执行用例,运行后无报告文件生成
环境:mac os:pytest + parallel + allure
示例代码:
#test_parallel.py
import pytest
from time import sleep
import yaml
class Test_parallel():
@pytest.mark.parametrize('args',yaml.safe_load(open('./yaml/testcase.yaml')))
def test_case(self,args):
print(args)
sleep(2)
#testcase.yaml
- 1
- 2
- 3
实验过程:
- 不适用多线程运行30个用例
在终端执行命令 pytest test_parallel.py --alluredir report,可以看到执行要60秒确实很慢,报告可以正常生成
- 使用parallel 运行用例
在终端执行命令 pytest --workers auto --tests-per-worker auto test_parallel.py --alluredir report_pa,可以看到执行只要2.14秒,启动了8个进程,4个线程几乎是30个并发执行了,但是报告文件夹下午json文件
3.使用插件xdist运行用例
在终端执行命令 pytest -n auto test_parallel.py --alluredir report_xdist ,可以看到自动识别了8个核心启动了8个进程,执行速度是9.03秒,无启用线程(不支持多线程),allure报告也支持
实验结论:
1.pytest_parallel 不支持allure报告,可能是实现原理不是主进程来分发任务执行再进行整合,等有时间看看实现原理再做分析。
2.pytest_xdist 可以支持allure报告,但是不支持多线程,所以执行速度上没有parallel快(9秒:2秒),但是已经比不并发执行快很多了(60秒)
求助:大神有了解parallel为什么不支持allure的请给出答案,最好还能给出解决方案