自动化框架-pytest(二)

pytest-html生成报告
Pytest-HTML是一个插件,它可以生成漂亮且容易阅读的HTML测试报告。
安装插件:

pip install pytest-html

运行测试并生成报告:

pytest --html=report.html

查看报告:
打开生成的HTML报告文件,可以查看测试结果的摘要、详细的测试用例执行信息、失败用例的堆栈跟踪等。
pytest-html添加图片

from pytest_html import extras

def test_add_img(extra):
	def image_to_base64(image path):
	import base64
	""这个函数是将图片转化为base64数据“”
	with open(image_path,"rb") as image_file:
		encoded_string = base64.b64encode(image_file.read())
		return encoded_string,decode('utf-8')
# 添加图片文件
image_path ="/VoLumes/huace/Pytest/你好.jpg" # 图片路径
extra.append(extras.jpg(image_path))	# 添加图片

#添加base64格式的图片
base64_data = image_to_base64(image_path)
extra.append(extra.image(base64_data))

#运行文件
import pytest

pytest.main(['--html=report/report.html','--self-contained-html'])

pytest-html报告中乱码解决
标题乱码解决:
在这里插入图片描述
内容乱码解决:
在这里插入图片描述
allure-pytest生成测试报告
下载地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
Allure安装:
下载安装包,解压到指定路径,进入到allure的bin路径下,复制bin的完整路径,添加到系统环境变量的path之中
启动cmd,运行allure --version指令,如果在控制台显示有allure版本信息则表示安装成功
allure-pytest插件安装:

pip install allure-pytest

运行生成测试报告:

import pytest
pytest.main(['--alluredir','alure_result','--clean-alluredir'])#获取测试结果,并以allure的数据格式保存
import os
os.system('allure generate --clean ./allure_result -o ./allure_report')#通过allure的数据进行报告生成

allure-pytest的乱码解决
1.将pycharm配置到环境变量中,重启pycharm
在这里插入图片描述
2.修改pycharm编码
在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值