From: https://www.cnblogs.com/fnng/p/4768239.html

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

2015-08-29 00:40 by 虫师, ... 阅读, 0 评论, 收藏, 编辑

  继续pytest单元测试框架的学习,pytest可以生成多种类型的测试报告。这一节就来学习pytest如何生成测试报告。

  创建test_calss.py 测试用例文件,这里以测试该文件为例。

#coding=utf-8

class TestClass:

    def test_one(self):
x = "this"
assert "h" in x def test_two(self):
x = "hello"
assert x == "hi"

生成resultlog文件

创建普通的结果文件:

> py.test test_class.py  --resultlog=./log.txt

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

. test_class.py::TestClass::()::test_one
F test_class.py::TestClass::()::test_two
self = <test_class.TestClass instance at 0x000000000307C788> def test_two(self):
x = "hello"
> assert x == "hi"
E assert 'hello' == 'hi'
E - hello
E + hi test_class.py:11: AssertionError

生成JunitXML文件

> py.test test_class.py  --junitxml=./log.xml

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

<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="1" name="pytest" skips="0" tests="2" time="0.015">
<testcase classname="test_class.TestClass" name="test_one" time="0.0"/>
<testcase classname="test_class.TestClass" name="test_two" time="0.00300002098083">
<failure message="assert &apos;hello&apos; == &apos;hi&apos;
- hello
+ hi">self = &lt;test_class.TestClass instance at 0x000000000309C948&gt; def test_two(self):
x = &quot;hello&quot;
&gt; assert x == &quot;hi&quot;
E assert &apos;hello&apos; == &apos;hi&apos;
E - hello
E + hi test_class.py:11: AssertionError
</failure>
</testcase>
</testsuite>

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

创建测试用例的URL  

> py.test test_class.py  --pastebin=all

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

https://bpaste.net/show/4815ce13c164

这样的结果展示将非常友好。

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

> py.test test_class.py  --pastebin=failed

生成html测试报告

  当然,更多时候,我们希望pytest能生成漂亮的测试报告。这需要安装pytest的扩展--pytest-html。

> pip install pytest-html     # 通过pip安装pytest-html

cmd命令提示符下执行测试文件:

>py.test test_class.py --html=./report.html

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

Python单元测试框架之pytest 2 -- 生成测试报告的更多相关文章

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

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

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

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

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

    继续pytest单元测试框架的学习,pytest可以生成多种类型的测试报告.这一节就来学习pytest如何生成测试报告. 创建test_calss.py 测试用例文件,这里以测试该文件为例. #cod ...

  4. Python单元测试框架:pytest

    (一)介绍 pytest是一个非常成熟的全功能的Python测试框架,主要特点有以下几点: 1.简单灵活,容易上手: 2.支持参数化: 3.能够支持简单的单元测试和复杂的功能测试,还可以用来做sele ...

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

    对于测试来讲,不管是功能测试,自动化测试,还是单元测试.一般都会预设一个正确的预期结果,而在测试执行的过程中会得到一个实际的结果.测试的成功与否就是拿实际的结果与预期的结果进行比较.这个比的过程实际就 ...

  6. Python单元测试框架之pytest 1 ---如何执行测试用例

    From: https://www.cnblogs.com/fnng/p/4765112.html 介绍   pytest是一个成熟的全功能的Python测试工具,可以帮助你写出更好的程序. 适合从简 ...

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

    fixtures不太好翻译,可看作是夹心饼干最外层的两片饼干.通常用setup/teardown来表示.它主要用来包裹测试用例,为什么需要这样的饼干呢?我们以web自动化测试为例,例如,要测试的某系统 ...

  8. python单元测试框架笔记

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

  9. Pytest测试框架(五):pytest + allure生成测试报告

    Allure 是一款轻量级.支持多语言的开源自动化测试报告生成框架,由Java语言开发,可以集成到 Jenkins. pytest 测试框架支持Allure 报告生成. pytest也可以生成juni ...

随机推荐

  1. [LeetCode&Python] Problem 896. Monotonic Array

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...

  2. Python 金融数据分析库及相关框架

    BackTest框架库: PyAlgoTrade ZipLine 金融数据分析库: pandas

  3. 【HDOJ1531】【差分约束+添加超级源点】

    http://acm.hdu.edu.cn/showproblem.php?pid=1531 King Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. WEBapi在IIS发布注意事项-发布错误

    发布报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 解决方法: 1)打开IIS管理器 2)找到功能视图的目录浏览 3)双击进入后,点击右侧操作栏-启用

  5. crash - JNI WARNING: input is not valid modified utf-8: illegal continuation byte

    the key point is "Modified UTF-8" is not like "Regular UTF-8", a legal Rgular UT ...

  6. File file = new File("路径名") 路径名的2种写法

    项目的结构:相同颜色是同级的 bean的配置文件的读取和一般文件的读取有点差别的 public static void getValue(String key){ //传入"time&quo ...

  7. ClusterControl 强大免费数据管理工具

    几张参考图 galera 集群管理 多种数据库管理 组件架构 参考资料 https://severalnines.com/docs/intro.html        

  8. centos7 用yum安装java8

    1.查看yum源中是否有相关套件yum -y list java* 2.上图中可以看到有两个自己想用的套件,经过试验发现用yum install java-1.8.0-openjdk 时最后 /usr ...

  9. Linux内核设计基础(三)之定时器和时间管理

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/BlueCloudMatrix/article/details/29294529 内核知道连续两次时钟 ...

  10. css3新增内容

    1.css3边框 border-radius box-shadow border-image 2.背景 background-size background-origin 3.文本效果 text-sh ...