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. Refused to execute inline event handler because it violates the following Content Security Policy directive: "xxx". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...')

    /********************************************************************************* * Refused to exec ...

  2. [LeetCode&Python] Problem 628. Maximum Product of Three Numbers

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  3. File available()方法

    File类中的length()方法与IO中InputStream类中的available()方法功能重复? 只是返回值类型不同 前者返回long后者返回int   但本质上都一样表示文件的字节数  a ...

  4. annotation注释简单介绍

    元数据的作用 如果要对于元数据的作用进行分类,目前还没有明确的定义,不过我们可以根据它所起的作用,大致可分为三类: l         编写文档:通过代码里标识的元数据生成文档. l         ...

  5. ps教程

    http://www.16xx8.com/photoshop/xinshoujiaocheng/

  6. sparkStreaming获取kafka数据(java版本)

    环境 spark-2.2.0 kafka_2.11-0.10.0.1 jdk1.8 配置好jdk,创建项目并将kafka和spark的jar包添加到项目中,除此之外还需要添加spark-streami ...

  7. 20165313 《Java程序设计》第四周学习总结

    教材学习总结 public:1.用在类前.2.用在方法前 .3. 用在成员变量前 private:用在成员变量前 final1.用在类前2.用在方法前3.用在成员变量前 static:1.所有对象公有 ...

  8. hdu2255 奔小康赚大钱 二分图最佳匹配--KM算法

    传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊.村里共有n间房间,刚好有n家老百姓,考虑到每家都要有房住(如果有老百姓没房子住 ...

  9. 利用cookie存放模糊查询的信息

    将前台传入后台的查询条件,存放到cookie中,并加入响应对象中,将该查询条件存放入浏览器端.(会话cookie,存放在浏览器的内存中,浏览器关闭,cookie消失.[不设置路径,和生命周期]) 注意 ...

  10. POJ3904 Sky Code

    题意 Language:Default Sky Code Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3980 Accepte ...