Python单元测试框架:pytest常用测试报告类型

🍅 视频学习:文末有免费的配套视频可观看

🍅 关注公众号【互联网杂货铺】,回复 1 ,免费获取软件测试全套资料,资料在手,涨薪更快

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

1. allure测试报告

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_oneF reportdemo/test_report.py::TestReport::test_two self = <test_report.TestReport object at 0x7fd9c0a3eac0>      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文件,打开文件内容如下:

<?xml version="1.0" encoding="utf-8"?><testsuites>    <testsuite errors="0" failures="1" hostname="chenshifengdeMacBook-Pro.local" name="pytest" skipped="0" tests="2"               time="0.072" timestamp="2021-01-27T23:56:58.204464">        <testcase classname="reportdemo.test_report.TestReport" file="reportdemo/test_report.py" line="9"                  name="test_one" time="0.001"></testcase>        <testcase classname="reportdemo.test_report.TestReport" file="reportdemo/test_report.py" line="13"                  name="test_two" time="0.002">            <failure message="AssertionError: assert &apos;hello&apos; == &apos;hi&apos;  - hi  + hello">self = &lt;test_report.TestReport object at 0x7fa152b97790&gt;                 def test_two(self):                x = &quot;hello&quot;                &gt; assert x == &quot;hi&quot;                E AssertionError: assert &apos;hello&apos; == &apos;hi&apos;                E - hi                E + hello                 test_report.py:16: AssertionError            </failure>        </testcase>    </testsuite></testsuites>

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

4. 生成测试用例的URL

执行命令:

pytest test_report.py  --pastebin=all

复制打印结果最后生成的session-log测试报告链接到浏览器:

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

 pytest test_class.py  --pastebin=failed

5. 生成html测试报告

通过pip安装pytest-html

 pip install pytest-html  

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

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

指定在当前目录下生成report.html文件,打开测试文件:

最后祝大家都能找到心仪的工作,快乐工作,幸福生活,广阔天地,大有作为。我也整理了一波之前发布的软件测试文档【点击文末小卡片免费领取】,无套路领取!

同时,在这我为大家准备了一份软件测试视频教程(含面试、接口、自动化、性能测试等),就在下方,需要的可以直接去观看,也可以直接【点击文末小卡片免费领取资料文档】

软件测试视频教程观看处:

【2024最新版】Python自动化测试15天从入门到精通,10个项目实战,允许白嫖。。。

  • 16
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值