Pytest知识整合小记(七、pytest其他插件)

许多插件可以简化很多工作,避免重复造轮子,以下插件是需要pip安装的

一、pytest-repeat

一句话说明:

重复运行测试。

运行指令:pytest --count=2 -v -k test_xxxx

二、pytest-xdist

一句话说明:

并行运行测试。

运行指令:pytest -v -k test_xxxx -n 10

代表并发10条线程同时运行不同的十条用例。

三、pytest-html

一句话说明:

测试生成的测试报告

运行指令:pytest --html=report.html

相对于上一篇的胡里花哨测试报告,这个测试报告就简单的多,但很容易使用,直接一个指令搞定。

四、pytest-timeout

一句话说明:

为测试设置时间限制

运行指令:pytest --timeout=0.5 -x test_xxxx.py

五、pytest-rerunfailures

一句话说明:

用例失败重跑

运行指令:pytest --reruns 1 --html=report.html --self-contained-html

@pytest.mark.xxxxx(reruns=6, reruns_delay=2)

总结:至此,pytest的内容七七八八归纳的差不多了。

posted @ 2025-05-14 15:26  寻虫测试  阅读(14)  评论(0)    收藏  举报