遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】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

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

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

  

示例

1
2
3
4
5
6
7
8
9
10
11
12
#!/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 @   全栈测试笔记  阅读(227)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
浏览器标题切换
浏览器标题切换end
点击右上角即可分享
微信分享提示