遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

pytest简易教程(34):pytest常用插件 - 测试报告(pytest-html)

 

pytest简易教程汇总,详见https://www.cnblogs.com/uncleyong/p/17982846

关于pytest-html

通过命令行方式,生成xml/html格式的测试报告,存储于用户指定路径

报告会覆盖上一次的

 

插件安装

pip install pytest-html

 

使用方式

命令行格式:pytest --html=./report/report.html

也可以配置文件添加参数:

[pytest]
addopts = -vs --html=./report/report.html

  

示例

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/

def test_a():
    assert 1==1
    print("---test_a")
def test_b():
    assert 1==2
    print("---test_b")

  

结果:

 

自动创建了report目录,css是独立的

 

浏览器打开

 

可以看到不同状态用例数量,还可以展开看详情

 

另外,为了方便分享报告,可以把css样式合并到html里,添加参数:--self-contained-html

命令:pytest case\test_qzcsbj.py -vs --html=./report/report.html --self-contained-html

生成的报告:

 

报告的不足

报告不是很美观,功能比较简单。

 

下一篇分享精美的allure报告。

 

posted @ 2024-02-24 10:47  全栈测试笔记  阅读(143)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end