先前博客有介绍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. SpringCloud 源码系列(6)—— 声明式服务调用 Feign

    SpringCloud 源码系列(1)-- 注册中心 Eureka(上) SpringCloud 源码系列(2)-- 注册中心 Eureka(中) SpringCloud 源码系列(3)-- 注册中心 ...

  2. Codeforces Round #695 (Div. 2)

    比赛地址 A (水题) 题目链接 题目: 给出\(n\)个面板,每个面板初始时间相同,每过1s面板上数字会加1(数字在\(0\sim9\)循环播放),任意时刻选择一个面板\(x\)使他的时间停止,其他 ...

  3. Spring(3) --事务,隔离级别,设计模式

    什么是事务?事物的四大特性? 事务是指单个逻辑工作单元执行的一系列操作(ACID),这些操作要么全部执行,要么全部不执行,是不可中断的. (1)原子性(Atomicity)是指事务所有操作是不可中断的 ...

  4. SpringBoot入门及深入

    一:SpringBoot简介 当前互联网后端开发中,JavaEE占据了主导地位.对JavaEE开发,首选框架是Spring框架.在传统的Spring开发中,需要使用大量的与业务无关的XML配置才能使S ...

  5. web元素定位和appium-app元素定位

    一.web页面元素定位工具介绍 1.打开google浏览器,按F12进入开发者模式,如下图: 2.用鼠标点击下图红色框中的箭头--然后鼠标移动到web页面的元素上(此处为百度框),会自动定位到对应的h ...

  6. Spring Boot 计划任务中的一个“坑”

    计划任务功能在应用程序及其常见,使用Spring Boot的@Scheduled 注解可以很方便的定义一个计划任务.然而在实际开发过程当中还应该注意它的计划任务默认是放在容量为1个线程的线程池中执行, ...

  7. SonarQube学习(六)- SonarQube之扫描报告解析

    登录http://192.16.1.105:9000,加载项目扫描情况 点击项目名称,查看报告总览 开发人员主要关注为[问题]标签页. 类型 主要关注为bug和漏洞. 其中bug是必须要修复的,漏洞是 ...

  8. 【一天一个知识点系列】- Http之状态码

    状态码 简介 HTTP 状态码负责表示客户端 HTTP 请求的返回结果. 标记服务器端的处理是否正常. 通知出现的错误等工作 作用及类别 作用:状态码告知从服务器端返回的请求结果 状态码的类别 注意: ...

  9. 使用Swagger2

    一.Swagger2是什么? Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务. 优点: 及时性 (接口变更后,能够及时准确地通知相关前后端开 ...

  10. django中的几种返回模版的方式

    redirect方法-----(重定向) # 首先导入redirect方法, from django.shortcuts import redirect 在函数中写一个返回值 return redir ...