先前博客有介绍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 = <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测试报告链接到浏览器:https://bpa.st/UW2IG



当然,你也可以只选择展示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文件,打开测试文件:

Python单元测试框架pytest常用测试报告类型的更多相关文章

  1. python单元测试框架pytest

    首先祝大家国庆节日快乐,这个假期因为我老婆要考注会,我也跟着天天去图书馆学了几天,学习的感觉还是非常不错的,这是一篇总结. 这篇博客准备讲解一下pytest测试框架,这个框架是当前最流行的python ...

  2. 【Pytest】python单元测试框架pytest简介

    1.Pytest介绍 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高.根据pytest的官方网站介绍 ...

  3. python单元测试框架——pytest

    官网:https://docs.pytest.org/en/latest/ pytest帮你写出更好的程序 1.An example of a simple test:(一个简单的例子),命名为tes ...

  4. python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)

    pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...

  5. Python单元测试框架之pytest 2 -- 生成测试报告

    From: https://www.cnblogs.com/fnng/p/4768239.html Python单元测试框架之pytest -- 生成测试报告 2015-08-29 00:40 by ...

  6. Python单元测试框架之pytest 3 -- fixtures

    From: https://www.cnblogs.com/fnng/p/4769020.html Python单元测试框架之pytest -- fixtures 2015-08-29 13:05 b ...

  7. Python单元测试框架之pytest 4 -- 断言

    From: https://www.cnblogs.com/fnng/p/4774676.html Python单元测试框架之pytest -- 断言 2015-08-31 23:57 by 虫师, ...

  8. python单元测试框架笔记

    目录 单元测试概述 什么是单元测试 单元测试什么进行? 单元测试由谁负责? 单元测试需要注意 单元测试覆盖类型 python 单元测试框架 unittest pytest 测试框架 单元测试概述 什么 ...

  9. [译]PyUnit—Python单元测试框架(1)

    1. 原文及参考资料 原文链接:http://docs.python.org/2/library/unittest.html# 参考文档: http://pyunit.sourceforge.net/ ...

随机推荐

  1. Npoi XWPF Word 导出时插入图片无法显示 bug 完美解决

    一.来自客户的需求 最近客户来个新需求生成一个word 标签纸,并且需要在标签纸上插入一个logo,并且将erp 中的数据取出来自动写在文档上,不由得淡淡一笑,这不难呀! 于是乎我就写下了这样的代码: ...

  2. 【函数分享】每日PHP函数分享(2021-1-9)

    implode() 将一个一维数组的值转化为字符串. string implode ( string $glue , array $pieces ) 参数描述 glue     默认为空的字符串. p ...

  3. LeetCode 二分查找模板 III

    模板 #3: int binarySearch(vector<int>& nums, int target){ if (nums.size() == 0) return -1; i ...

  4. 【Java】计算机软件、博客的重要性、编程语言介绍和发展史

    之前学得不踏实,重新复习一遍,打扎实基础中. 记录 Java核心技术-宋红康_2019版 & Java零基础学习-秦疆 文章目录 软件开发介绍 软件开发 什么是计算机? 硬件及冯诺依曼结构 计 ...

  5. kubernets之从应用访问pod元数据以及其他资源

    一  downwardAPI的应用 1.1  前面我们介绍了如何通过configmap以及secret将配置传入到pod的容器中,但是传递的这些都是预先能够安排和只晓得,对于那些只有当pod创建起来之 ...

  6. kubernets之configMap和secret

    一  如何有效且更好的将配置写到pod的容器中 考虑一个问题,就是在传统的应用中,程序里面需要的配置一般以配置文件的形式或者shell脚本里面的参数是在执行的时候在命令行里面进行添加,但是在kuber ...

  7. CodeMonke少儿编程第1章 step与turn

    第1章 step与turn 目标 了解游戏舞台的各组成部分 掌握step和turn指令的用法 说起计算机,对于不了解它的人来说,也许会感到有些神秘,其实不然,它不过是能够接收指令并且按照指令执行的一种 ...

  8. 基于.NET Core的优秀开源项目合集

    开源项目非常适合入门,并且可以作为体系结构参考的好资源, GitHub中有几个开源的.NET Core项目,这些项目将帮助您使用不同类型的体系结构和编码模式来深入学习 .NET Core技术, 本文列 ...

  9. SW3516中文资料书

    SW3516 是一款高集成度的快充车充芯片, 支持 A+C 口任意口快充输出, 支持双口独立限流.其集成了 5A 高效率同步降压变换器, 支持 PPS/PD/QC/AFC/FCP/SCP/PE/SFC ...

  10. 细数JS中实用且强大的操作符&运算符

    目录 1,前言 2,代码+应用 2.1,短路运算符 || 2.2,短路运算符 && 2.3,零合并操作符 ?? 2.4,可选链操作符 ?. 2.5,位运算符 & 和 | 2.6 ...