其他分享
首页 > 其他分享> > Pytest学习(十六)- 分布式测试插件之pytest-xdist的使用

Pytest学习(十六)- 分布式测试插件之pytest-xdist的使用

作者:互联网

前言

类似TestNG中的多线程并发执行用例,只是python叫多进程,目的就是批量执行测试脚本,从而节省自动化测试时间。

分布式执行用例的设计原则(重中之重的重点)

安装插件

pip3 install pytest-xdist -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

pytest-xdist特性

使用方法

执行某个目录下所有用例

1、不使用分布式测试

命令行:

pytest -s

所需时间如下:

2、使用分布式测试

命令行:

pytest -s -n auto

所需时间如下:

3、指定需要多少个CPU来跑用例

pytest -s -n 2

效果如图:

4、pytest-xdist和pytest-html结合使用

示例命令:

pytest -s -n auto --html=report.html --self-contained-html

5、pytest-xdist按照一定的顺序执行

pytest-xdist默认是无序执行的,可以通过 --dist 参数来控制顺序

标签:插件,--,xdist,用例,pytest,测试,执行
来源: https://www.cnblogs.com/longronglang/p/14056302.html