Python单元测试框架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 = <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 'hello' == 'hi'
- hi
+ hello">self = <test_report.TestReport object at 0x7fa152b97790>
def test_two(self):
x = "hello"
> assert x == "hi"
E AssertionError: assert 'hello' == 'hi'
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常用测试报告类型的更多相关文章
- python单元测试框架pytest
首先祝大家国庆节日快乐,这个假期因为我老婆要考注会,我也跟着天天去图书馆学了几天,学习的感觉还是非常不错的,这是一篇总结. 这篇博客准备讲解一下pytest测试框架,这个框架是当前最流行的python ...
- 【Pytest】python单元测试框架pytest简介
1.Pytest介绍 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高.根据pytest的官方网站介绍 ...
- python单元测试框架——pytest
官网:https://docs.pytest.org/en/latest/ pytest帮你写出更好的程序 1.An example of a simple test:(一个简单的例子),命名为tes ...
- python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)
pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...
- Python单元测试框架之pytest 2 -- 生成测试报告
From: https://www.cnblogs.com/fnng/p/4768239.html Python单元测试框架之pytest -- 生成测试报告 2015-08-29 00:40 by ...
- Python单元测试框架之pytest 3 -- fixtures
From: https://www.cnblogs.com/fnng/p/4769020.html Python单元测试框架之pytest -- fixtures 2015-08-29 13:05 b ...
- Python单元测试框架之pytest 4 -- 断言
From: https://www.cnblogs.com/fnng/p/4774676.html Python单元测试框架之pytest -- 断言 2015-08-31 23:57 by 虫师, ...
- python单元测试框架笔记
目录 单元测试概述 什么是单元测试 单元测试什么进行? 单元测试由谁负责? 单元测试需要注意 单元测试覆盖类型 python 单元测试框架 unittest pytest 测试框架 单元测试概述 什么 ...
- [译]PyUnit—Python单元测试框架(1)
1. 原文及参考资料 原文链接:http://docs.python.org/2/library/unittest.html# 参考文档: http://pyunit.sourceforge.net/ ...
随机推荐
- C语言的类型大小
C语言的类型大小 设计程序的时候我们一般会考虑的尽量的周全,尤其是像C这样的静态类型语言. 有一些溢出的问题就源于没有搞清楚变量的大小范围,所以我们编写的时候需要特别注意 C的整形(整数类型)大小 C ...
- 【System】paging和swaping之间的区别是什么?
分析paging和swapping的区别,首先要了解内存管理 当虚拟内存用二级存储(物理磁盘)作为主存的扩展时,内核会尽力保持最活跃的数据在主存中.有一下两个内核例程做这件事情: 1.交换(swapp ...
- kubernets集群的安全防护(上)
一 了解认证机制 1.1 API的服务器在接收来自客户端的请求的时候会对发起的用户进行几个步骤 认证插件进行认证,确认发起的用户是外部用户,还是集群中的某个命名空间里面的pod 确认用户属于哪个 ...
- CSAPP:Lab0 -Docker搭建纯净Linux环境
1. 安装docker 在mac-os下我们可以利用homebrew很容易的安装docker. brew install docker 当然去官网下载也很容易 Empowering App Devel ...
- Apache目录详解
Apache的主要目录和配置文件理解 参考链接:http://httpd.apache.org/docs/2.4/misc/security_tips.html 一.Apache主要配置文件注释(演示 ...
- MongoDB数据库,一些的筛选过滤查询操作和db.updae()更新数据库记录遇到的坑。
缘由:使用MongoDB时遇到一些需要查询/更新操作指定某些字段的业务场景 查询和更新指定字段就需要进行简单的筛选和过滤,也能在大数据量时减少查询消耗时间 1. 查询数据库某些指定字段,同时默认返回_ ...
- linux GPU上多个buffer间的同步 —— ww_mutex、dma-fence的使用 笔记
原文链接:https://www.cnblogs.com/yaongtime/p/14111134.html WW-Mutexes 在GPU中一次Render可能会涉及到对多个buffer的引 ...
- Numpy的一些学习记录
Numpy的一些记录 产生numpy.array的方式 import numpy as np arr1 = np.array([1, 2, 3]) print(arr1) arr2 = np.zero ...
- python(pymysql操作数据库)
第一种方式 import pymysql # 打开数据库连接 db = pymysql.connect(host="192.168.88.11", user="root& ...
- 超微服务器重置ipmi登录密码
超微服务器的ipmi登录密码不对,需要重置但是bios内并没有找到可以设置的选项. 以下是解决办法: 安装IPMITOOLyum install ipmitool -y 执行以下命令加载模块:modp ...