您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 淮南分类信息网,免费分类信息发布

分析Python接口自动化-Pytest-Html

2023/4/9 15:26:27发布32次查看
前言从这之后,越来越多人发现自动化测试工具的价值所在,从而影响很多人的选择。
小编在搭建组内接口自动化框架过程中使用过两个html报告框架,pytest-html和allure,本文主要介绍下pytest-html。
pytest-html是个插件,pytest用于生成测试结果的html报告,兼容python27和python36。
pytest-html介绍
1github源码地址
githubcompytest-devpytest-html
2pip安装pip install pytest-html
3执行方法 pytest --html=reporthtml
执行完后会在当前目录生成一个reporthtml的报告文件
4指定报告路径
加入目标目录即可pytest --html=reporthtmlreporthtml
5报告独立展示
上面生成的报告,css是独立的,分享报告邮件的时候样式就会丢失,不好阅读,也无法筛选。
为了更好的展示测试报告,可以把css样式合并到html里。 pytest --html=reporthtml --self-contained-html
6失败重试
失败重试依赖pytest-rerunfailures插件
pip install pytest-rerunfailures
用例失败再重跑一次,需要再命令行加参数--reruns
reruns参数有2个用法:
--reruns=reruns reruns是失败重跑的次数,默认为0
--reruns-delay=reruns_delay reruns_delay是失败后间隔多少s重新执行。 pytest --reruns 1 -html=reporthtml --self-contained-html
pytest-html在接口框架中的使用
1python smtp发送邮件def sendmail(to, title, mail_msg, from="test@sogou-inccom", cc=none):
"""
:param from: 发件人
:param to: 收件人
:param cc: 抄送
:param title: 邮件标题
:param mail_msg: 邮件内容(可以是html,或文本)
:return:
"""
message = mimetext(mail_msg, 'html', 'utf-8')
message['from'] = header(from, 'utf-8')
message['to'] = header("; "join(to), 'utf-8')
if cc is not none:
message['cc'] = header("; "join(cc), 'utf-8')
message['subject'] = header(title, 'utf-8')
try:
smtpobj = smtplibsmtp()
smtpobjconnect(mail_host, 25) # 25 为 smtp 端口号
smtpobjlogin(mail_user, mail_pass)
smtpobjsendmail(from, to, messageas_string())
print("邮件发送成功")
except smtplibsmtpexception:
print("error: 无法发送邮件")
2pytest-html执行、邮件发送 # 利用pytest-html生成html报告
shell = shell()
cmd = 'pytest --reruns 1 --html=reporthtmlreporthtml --self-contained-html'
# 邮件发送
try:
file_name = html_report_path + '' + 'reporthtml'
f = open(file_name, 'rb')
message = fread()
fclose()
receiver = ["chenpeng01@sogou-inccom"]
cc = [""]
exsendemailsendmail(to=receiver, title="【奇点广告】接口自动化测试报告", mail_msg=message, cc=cc)
except exception as e:
logerror('发送邮件失败,请检查邮件配置')
raise3测试报告展示
淮南分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录