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报告。

更多推荐