pytest常用插件
https://pypi.org
【pytest-html】
用途:生成HTML测试报告
文档: https://pytest-html.readthedocs.io/en/latest/installing.html
安装:
pip install pytest-html
配置(命令行参数):
pytest -html=report.html --self-contained-html
【pytest-xdist】
用途:并发执行用例
文档: https://pytest-xdist.readthedocs.io/en/stable/
安装:
pip install pytest-xdist
配置(命令行参数): 可选线程数:0,1,2,3,……n,auto。
-n 9
注意:
1.多进程额外增加资源
2.多进程乱序
3.多进程竞争资源(-s参数失效)
4.auto自动判断进程数(CPU内核数)
【python-order】
用途:定义用例的执行顺序,值越小越先执行
文档:https://pytest-order.readthedocs.io/en/latest/
安装:
pip install pytest-order
配置(标记):@pytest.mark.order(序号)
import pytest
class Test_A:
@pytest.mark.order(3)
def test_ccc_A_1(self, f):
print("我是ccc用例test_A_1内容,正在执行")
print("收到了fixture的返回值", f)
@pytest.mark.order(3)
def test_ccc_A_2(self, f):
print("我是ccc用例test_A_2内容,正在执行")
print("收到了fixture的返回值", f)
class Test_B:
@pytest.mark.order(3)
def test_ccc_B_1(self, f):
print("我是ccc用例test_B_1内容,正在执行")
print("收到了fixture的返回值", f)
@pytest.mark.order(2)
def test_ccc_B_2(self, f):
print("我是ccc用例test_B_2内容,正在执行")
print("收到了fixture的返回值", f)
@pytest.mark.order(1)
def test_ccc_C(f):
print("我是ccc用例test_C内容,正在执行")
print("收到了fixture的返回值", f)
顺序规则:
先执行有order的用例,再执行没有order的用例
先执行order较小的用例,再执行order较大的用例
order全局生效,可以跨文件、跨目录
【pytest-rerunfailures】
用途:用例失败时自动重试
文档:https://github.com/pytest-dev/pytest-rerunfailures
安装
pip install pytest-rerunfailures
配置(命令行参数): --reruns 重试次数 --reruns-delay 重试间隔,单位秒
--reruns 5 --reruns-delay 1
【pytest-result-log】
用途:把用例的执行结果保存到日志列表
文档: https://mp.weixin.qq.com/s/f90fcj54pKvebnBahIlIog
安装:
pip install pytest-result-log
配置(pytest.ini)
[pytest]
addopts = tests/bbb/test_ss.py -vs --strict
#注册标签
markers =
api
ui
ut
e2e:'marks tests as login'
log_file=./logs/pytest.log
log_file_level=info
log_file_format=%(levelname)-8s %(asctime)s [%(name)s:%(lineno)s] : %(message)s
log_file_date_format= %Y-%m-%d %H:%M:%S
;记录用例执行结果
result_log_enable=1
;记录用例分割线
result_log_separator=1
;分割线等级
result_log_level_separator =warning
;异常信息等级
result_log_level_verbose=info
颜色:pycharm插件 file->settings->plugins->Ideolog
【allure-pytest】
用途:生成allure数据文件
安装:
pip install allure-pytest
配置(pytest.ini):
[pytest]
addopts = tests/bbb/test_ss.py -vs --strict --alluredir=temps --clean-alluredir
#注册标签
markers =
api
ui
ut
e2e:'marks tests as login'
log_file=./logs/pytest.log
log_file_level=info
log_file_format=%(levelname)-8s %(asctime)s [%(name)s:%(lineno)s] : %(message)s
log_file_date_format= %Y-%m-%d %H:%M:%S
;记录用例执行结果
result_log_enable=1
;记录用例分割线
result_log_separator=1
;分割线等级
result_log_level_separator =warning
;异常信息等级
result_log_level_verbose=info
本插件只生成数据,不生成报告:
1.创建目录temps
2.清空目录内容
3.在目录中创建数据文件

被折叠的 条评论
为什么被折叠?



