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
相关推荐
春日见7 小时前
TEST文件夹:Pytest,集成测试,单元测试
服务器·人工智能·驱动开发·单元测试·计算机外设·集成测试·pytest
TRACER~859 小时前
项目实战:pandas+pytest+allure+adb
adb·pandas·pytest
Franciz小测测1 天前
Pytest 并发分组执行引擎(支持UI / 接口自动化测试):从设计到工程落地
pytest
小猪咪piggy2 天前
【接口自动化】(2) pytest 测试框架
运维·自动化·pytest
忘忧记2 天前
Pytest + Requests + YAML 数据驱动+日志模块
网络·python·pytest
清水白石0083 天前
pytest Fixture 设计实战指南:作用域、依赖链、自动清理与测试资源高效复用
python·pytest
亚马逊云开发者4 天前
Amazon Nova Act 浏览器自动化测试实战:AI 驱动的端到端测试 + pytest 集成 + OpenClaw 场景落地
人工智能·pytest
cendy-LL5 天前
自动化测试之Pytest框架
pytest
我的xiaodoujiao5 天前
API 接口自动化测试详细图文教程学习系列7--相关Python基础知识6
python·学习·测试工具·pytest
忘忧记5 天前
pytest + YAML + requests`简单实例化
网络·pytest