pytest利用pytest-html生成html报告

1、安装pytest-html

使用命令pip install pytest-html -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com来安装pytest-html
官方文档地址:pytest-html官方链接

2、书写pytest测试用例

书写测试用例文件Test_simple.py

#-*- coding: utf-8 -*-
import pytest

class Test_simple():
    def test_case1(self):
        tof = True
        assert tof

    def test_case2(self):
        tof = False
        assert tof

3、运行用例

使用命令行方式运行用例:

pytest --html=report/report.html

即可在pytest运行目录下的report文件夹下看到report.html和一个包含css文件的文件夹。
但是这种方式无法将这个html文件放入邮件正文。故可以用如下方式来生成一个包含css样式的html格式报告:

pytest --html=report/report.html --self-contained-html

这样就只有一个html文件,如下:
在这里插入图片描述
测试报告结果html如下:
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章