pytest(6): pytest-html和allure报告生成

一、关于pytest-html安装

pytest-html属于pytest的一个插件,使用它需要先安装

pip install pytest-html
pytest可以生成多种样式的结果:

  • 生成JunitXML格式的测试报告,命令:--junitxml=path

  • 生成ResultLog格式的测试报告,命令:--resultlog=report/log.txt

  • 生成Html格式的测试报告,命令:--html=OutPuts/reports/report.html(相对路径)

生成html报告

if __name__ == '__main__':
    # 生成python-html报告
    pytest.main(['-s', '-v', '--html=OutPuts/reports/report.html'])

二、关于allure安装

allure是跟pytest一起集成使用的,所以需要同时安装pytest以及allure-pytest插件:

pip install pytest
pip install allure-pytest

  • 前置条件jdk必须先安装,基于这个环境才能运行
    安装allure从Maven Center下载最新的安装包(选择最新版本):
    https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline

1.选择zip包:

2.将包解压到任何一个目录,建议不要选C盘或者路径很深的。比如G:\allure-2.13.0

3.跳转到解压后的bin目录下面,windows下执行allure.bat。其它平台执行allure

4.配置allure的环境变量:

5.测试安装是否OK

二、生成allure测试报告文件

使用命令行:—alluredir=Outputs/allure (相对于pytest命令所在目录的测试报告目录)

if __name__ == '__main__':
    # 生成allure报告文件
    pytest.main(['-s', '-v', '--alluredir=OutPuts/allure'])

所有用例执行完,在OutPuts/allure目录下会生成一些报告文件

三、生成html页面的allure测试报告

1.查看allure报告
  使用命令行:allure serve 测试结果文件目录(OutPuts/allure)

i

2.生成html格式的allure报告
  使用命令行:allure generate 测试结果文件目录 -o 输入html文件的目录 --clean

--clean表示每次执行该命令行都先清除输入html文件的目录下的文件

比如:allure generate OutPuts/allure -o OutPuts/allure_html --clean

对该文件右键—>Open in Browser—>Chrome,打开测试报告

pytest.ini 配置

[pytest]
markers =
    smoke:marks tests as smoke.
    demo:marks tests asa demo.
testpaths=./cases
addopts=-vsq --reruns 2 --html=output/report/html/report.html --alluredir=output/report/allure_report

base_url=https://www.baidu.com/


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值