pytest常用插件介绍
pytest-repeat 重复运行测试
如果希望在一个会话中重复运行测试,则可以使用pytest-repeat插件
安装插件后,在命令行使用选项–count=2,可以指定每个测试用例运行两次
如:
pytest --count=2
pytest-xdist 并行运行测试用例
通常测试用例都是依次执行的,因为有些资源一次只能被一个测试用例访问
如果你的测试用例不需要访问共享资源,那么就可以用过并行来提速
安装pytest-xdist后,在命令行使用-n numprocess来指定进程数
如 pytest -n 2
pytest-timeout 为测试设置时间限制
pytest-html 为测试生成HTML报告
安装完成后,使用命令行–html
pytest --html=report_name.html
pytest-ordering 用于改变测试用例的执行顺序
使用装饰器@pytest.mark.run(order=2),可以改变测试用例的顺序
pytest-rerunfailures 失败用例重跑
–reruns num 失败用例重跑
allure-pytest 用于生成美观的测试报告
pytest有很多插件,相关的插件可以查看 https://pypi.python.org
输入pytest-或者-pytest可以获得相关的插件