pytest 常用测试报告类型

先前博客有介绍pytest测试框架的安装及使用,现在来聊聊pytest可以生成哪些测试报告

1.allure测试报告

关于allure报告参见先前的一篇博文: https://www.cnblogs.com/feng0815/p/13792188.html ,这里不再赘述

2.生成resultlog文件

#!/usr/bin/python
 -*- coding: UTF-8 -*-
"""
@author:chenshifeng
@file:test_report.py
@time:2021/01/27
"""
class TestReport:

    def test_one(self):
        x = "shifeng"
        assert "feng" in x

    def test_two(self):
        x = "hello"
        assert x == "hi"

执行命令:

pytest test_report.py  --resultlog=./resultlog.txt

指定当前路径下生成resultlog.txt文件,打开文件,内容如下:

. reportdemo/test_report.py::TestReport::test_one
F reportdemo/test_report.py::TestReport::test_two
 self = 
 
     def test_two(self):
         x = "hello"
 >       assert x == "hi"
 E       AssertionError: assert 'hello' == 'hi'
 E         - hi
 E         + hello
 
 test_report.py:16: AssertionError

3.生成JunitXML文件

执行命令:

pytest test_report.py  --junitxml=./resultlog.xml

同样指定在当前目录下生成resultlog.xml文件,打开文件内容如下:



    
        
        
            self = 

                def test_two(self):
                x = "hello"
                > assert x == "hi"
                E AssertionError: assert 'hello' == 'hi'
                E - hi
                E + hello

                test_report.py:16: AssertionError
            
        
    

创建这样的XML文件有有什么用? 主要是为了方便Jenkin或其它的持续集成工具读取。

4.生成测试用例的URL

执行命令:

pytest test_report.py  --pastebin=all

pytest 常用测试报告类型_第1张图片

复制打印结果最后生成的session-log测试报告链接到浏览器: https://bpa.st/UW2IG
pytest 常用测试报告类型_第2张图片

当然,你也可以只选择展示faile的测试用例

pytest test_class.py  --pastebin=failed

5.生成html测试报告
通过pip安装pytest-html

pip install pytest-html

在代码文件的当前目录下执行命令

pytest test_report.py --html=./report.html

pytest 常用测试报告类型_第3张图片

指定在当前目录下生成report.html文件,打开测试文件:
pytest 常用测试报告类型_第4张图片

资源分享

下面这些是我的收集和整理的资料,对于开始学习【软件测试】或是技能进阶的朋友来说,绝对是最全面的教程仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你
pytest 常用测试报告类型_第5张图片

关注【程序媛木子】微信公众号测试资源将免费获取。

你可能感兴趣的:(软件测试,编程语言,测试工程师,测试类型,接口测试)