pytest并发执行用例方案

背景

开始做新项目的UI自动化,需要考虑用例的并发执行,因为之前做的项目是通过插件pytest-parallel 0.1.1 + pytest-multithreading-allure 1.0.8来实现的,所以这次也打算用此方法,然而在实际使用过程中发现一些问题。

问题一

通过 pytest --workers n 运行后出现报错,错误是:AttributeError: Can't pickle local object 'pytest_addoption.<locals>.label_type.<locals>.a_label_type'
解决方法:由于运行环境是windows,查资料windows上要安装0.0.10版本, 之前都是在mac或者Linux环境上运行没有遇到此问题

问题二

pytest-parallel降级为版本0.0.10,再次运行,还是会报错,但错误是:

复制代码
............
AttributeError: '_Environ' object has no attribute 'putenv'

解决方法 : 参考https://github.com/kevlened/pytest-parallel/issues/89#issuecomment-797698926进行修改,修改后执行 pytest --tests-per-worker n 可以多线程运行, window上pytest --workers n 时,n只能是1

总结

  1. 经过上面的折腾终于解决了windows上使用pytest-parallel的问题,但是始终要去修改pytest-parallel中的内容,决定改为使用pytest-xdist,安装最新版本的pytest-xdist , 安装后执行 pytest -n n即可 , 发现pytest-xdist会导致scope=session的fixture设置失效,即导致每个用例都会执行一次此fixture,正常情况是只需要执行一次的,详见session失效的解决办法
  2. 如果运行环境是Linux或者mac,应该还是会优先选择pytest-parallel
相关推荐
小罗和阿泽1 小时前
接口测试系列 接口自动化测试 pytest框架(一)
pytest
补三补四9 小时前
pytest应用实践
pytest
Lary_c1 天前
【测试自动化】pytest + Allure 完整学习指南
运维·自动化·pytest
我的xiaodoujiao4 天前
API接口自动化测试详细图文教程学习系列1--序章
python·学习·pytest
我的xiaodoujiao4 天前
API 接口自动化测试详细图文教程学习系列2--相关Python基础知识
python·学习·测试工具·pytest
H_unique5 天前
博客接口自动化测试--搭建测试环境&库的介绍&安装allure
python·pytest·测试
真智AI6 天前
MCP+pytest自动重构回归:复刻ARIS循环
重构·pytest
零基础的修炼6 天前
自动化测试---pytest
pytest
鲜于言悠9057 天前
博客系统测试报告
python·功能测试·selenium·jmeter·测试用例·集成测试·pytest
0和1的舞者8 天前
高并发论坛系统:单元测试 + 接口自动化 + 性能测试 + CI/CD 全链路测试报告
java·测试开发·测试工具·jmeter·pytest·测试·测试报告