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. python调用caffe实现预测

    对于已经训练完成的caffemodel,对于单个的图片预测,用python接口来调用是一件非常方便的事情,下面就来讲述如何用python调用已经训练完成的caffemodel,以及prototxt,网 ...

  2. Linux 查看CPU信息、机器型号等硬件信息[转]

    查看CPU信息(型号) # cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c       8  Intel(R) Xeon(R) CPU    ...

  3. Django中的session于cookie的用法

    1.cookies 1.django 中使用 cookies 1.设置cookies的值(将数据保存到客户端) 语法: 响应对象.set_cookie(key,value,expires) key:c ...

  4. Socket远程桌面

    自建Socket转发,使用远程桌面(mstsc)连接家中电脑   网络结构图如下: 开题先放图,一切全靠编哈哈. 进入正题! 如图所示,我们需要一个公网服务器,利用公网服务器将内网的数据进行转发,从而 ...

  5. 1.Tensorflow的基本概念:

    1.Tensorflow的基本概念: 1.使用图(graphs)来表示计算任务 2.在被称之为会话(Session)的上下文(context)中执行图 3.使用tensor表示数据 4.通过变量(Va ...

  6. 原版win10

    windows10专业版:ed2k://|file|cn_windows_10_multiple_editions_x64_dvd_6848463.iso|4303300608|94FD861E824 ...

  7. CH5701 开车旅行

    题意 5701 开车旅行 0x50「动态规划」例题 描述 小A和小B决定利用假期外出旅行,他们将想去的城市从1到N编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 ...

  8. linux后台运行之&和nohup区别,模拟后台守护进程

    先来看一下&的使用 root@BP:~# cat test.sh #!/bin/bash while true do echo "linux">/dev/null d ...

  9. Sublime Text怎么快速建立一个html5页面模板

    在编辑器中输入一个半角英文的感叹号(!),然后按下TAB键

  10. MySQL通过Navicat实现远程连接

    直接使用Navicat通过IP连接会报各种错误,例如:Error 1130: Host '192.168.1.80' is not allowed to connect to this MySQL s ...