Pytest插件

Pytest插件

插件列表网址:https://plugincompat.herokuapp.com,包含了很多插件包

一、调整测试用例的执行顺序

安装:pip install pytest-ordering

在测试方法上加下面装饰器

@pytest.mark.last
#最后一个执行
@pytest.mark.run(order=1)
#第几个执行

二、用例失败重试

安装:pip install pytest-rerunfailures

命令行参数:--reruns n(重新运行次数),--reruns-delay m(等待运行秒数)

pytest --reruns 5

装饰器参数:reruns=n(重新运行次数),reruns_delay=m(等待运行秒数)

 @pytest.mark.flaky(reruns=5)

三、多重校验

如果需要多个断言,都执行就需要第三方插件 pytest-assume

安装:pip install pytest-assume

def test_add2(self):
    pytest.assume(add(1,2)==3)
    pytest.assume(add(1,4)==3)
    pytest.assume(add(2,2)==4)

四、pytest-html生成报告

安装:pip install pytest-html

命令行参数:--html=report.html

pytest --html=report.html
原文地址:https://www.cnblogs.com/lazy-sang/p/13700435.html