这里我们单独来看下关于如何生存测试报告

准备测试代码如下:

#coding: utf-

import pytest

@pytest.fixture()
def login():
print '输入账号、密码登录' def test_step_1(login):
print '用例步骤1:登录之后其它动作111' def test_step_2(): #不需要登录
print '用例步骤2: 不需要登录, 操作222' def test_step_3(login):
print '用例步骤3:登录之后其它动作333'

生成JunitXML 格式的测试报告

JunitXML报告是一种很常用的测试报告,比如可以和Jenkins进行集成,在Jenkins的GUI上显示Pytest的运行结果,非常便利。
运行完case后可以到report路径下去查看相应的xml文件,也可以在PyCharm打开该xml文件查看。

执行命令:

pytest -v test_smtpsimple.py --junitxml=log.xml

运行结果:

(wda_python) bash-3.2$ pytest -v test_smtpsimple.py --junitxml=log.xml
========================================================== test session starts ===========================================================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected items test_smtpsimple.py::test_step_1 PASSED [ %]
test_smtpsimple.py::test_step_2 PASSED [ %]
test_smtpsimple.py::test_step_3 PASSED [%] ---------------------------- generated xml file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.xml ----------------------------
======================================================== passed in 0.02 seconds ========================================================
(wda_python) bash-3.2$

生存的log.xml:

<?xml version="1.0" encoding="utf-8"?><testsuite errors="" failures="" name="pytest" skips="" tests="" time="0.023"><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_1" time="0.00126314163208"><system-out>输入账号、密码登录
用例步骤1:登录之后其它动作111
</system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_2" time="0.000802755355835"><system-out>用例步骤2: 不需要登录, 操作222
</system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_3" time="0.00115084648132"><system-out>输入账号、密码登录
用例步骤3:登录之后其它动作333
</system-out></testcase></testsuite>

生成result log格式的测试报告

(wda_python) bash-3.2$ pytest -s -v test_smtpsimple.py --resultlog=log.txt
========================================================== test session starts ===========================================================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected items test_smtpsimple.py::test_step_1 输入账号、密码登录
用例步骤1:登录之后其它动作111
PASSED
test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
PASSED
test_smtpsimple.py::test_step_3 输入账号、密码登录
用例步骤3:登录之后其它动作333
PASSED ============================================================ warnings summary ============================================================
/Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/lib/python2./site-packages/_pytest/resultlog.py:
/Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/lib/python2./site-packages/_pytest/resultlog.py:: PytestDeprecationWarning: --result-log is deprecated and scheduled for removal in pytest 5.0.
See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information.
_issue_warning_captured(RESULT_LOG, config.hook, stacklevel=) -- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================== passed, warnings in 0.01 seconds ==================================================
(wda_python) bash-3.2$

现在回提示过期, 生存的Log.txt

. test_smtpsimple.py::test_step_1
. test_smtpsimple.py::test_step_2
. test_smtpsimple.py::test_step_3

可以改成这样:

pytest -s -v test_smtpsimple.py > log.txt

生存的log.txt为

============================= test session starts ==============================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collecting ... collected items test_smtpsimple.py::test_step_1 输入账号、密码登录
用例步骤1:登录之后其它动作111
PASSED
test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
PASSED
test_smtpsimple.py::test_step_3 输入账号、密码登录
用例步骤3:登录之后其它动作333
PASSED =========================== passed in 0.01 seconds ===========================

生成Html格式的测试报告

html格式的测试报告在浏览器观看效果很好,还可以把这些测试报告放在Web服务器上。
首先,需要安装pytest-html插件。

pip install pytest-html

使用指令:

pytest -s -v test_smtpsimple.py --html=log.html

运行结果:

(wda_python) bash-3.2$ pytest -s -v test_smtpsimple.py --html=log.html
========================================================== test session starts ===========================================================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
metadata: {'Python': '2.7.15', 'Platform': 'Darwin-17.0.0-x86_64-i386-64bit', 'Packages': {'py': '1.7.0', 'pytest': '4.1.0', 'pluggy': '0.8.0'}, 'Plugins': {'html': '1.20.0', 'metadata': '1.8.0'}}
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
plugins: metadata-1.8., html-1.20.
collected items test_smtpsimple.py::test_step_1 输入账号、密码登录
用例步骤1:登录之后其它动作111
PASSED
test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
PASSED
test_smtpsimple.py::test_step_3 输入账号、密码登录
用例步骤3:登录之后其它动作333
PASSED --------------------------- generated html file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.html ---------------------------
======================================================== passed in 0.03 seconds ========================================================
(wda_python) bash-3.2$

生存的log.html用浏览器打开:

iOS自动化探索(七)自动化测试框架pytest - 测试报告的更多相关文章

  1. iOS自动化探索(四)自动化测试框架pytest - 安装和使用

    自动化测试框架 - pytest pytest是Python最流行的单元测试框架之一, 帮助更便捷的编写测试脚本, 并支持多种功能复杂的测试场景, 能用来做app测试也能用作函数测试 官方文档: ht ...

  2. python3: 自动化测试框架pytest

    最近在学习web自动化,所以在这里总结一下pytest框架. 其实pytest 和 unittest 都是自动化测试框架,但是pytest更好用一些,有以下几个优点:1)可以根据标签执行用例:2)?? ...

  3. iOS自动化探索(六)自动化测试框架pytest - fixtures

    Fixture介绍 fixture是pytest特有的功能,它用pytest.fixture标识,定义在函数前面.在编写测试函数的时候,可以将此函数名称做为传入参数,pytest将会以依赖注入方式,将 ...

  4. iOS自动化探索(五)自动化测试框架pytest - Assert断言的使用

    使用assert语句进行断言 pytest允许使用标准的python assert语法,用来校验expectation and value是否一致 代码演示: def func(): def test ...

  5. Python接口自动化测试框架: pytest+allure+jsonpath+requests+excel实现的接口自动化测试框架(学习成果)

    废话 最近在自己学习接口自动化测试,这里也算是完成一个小的成果,欢迎大家交流指出不合适的地方,源码在文末 问题 整体代码结构优化未实现,导致最终测试时间变长,其他工具单接口测试只需要39ms,该框架中 ...

  6. iOS自动化探索(十)代码覆盖率统计

    iOS APP代码覆盖率统计 今年Q3季度领导给加了个任务要做前后端代码覆盖率统计, 鉴于对iOS代码代码比较熟就选择先从iOS端入手,折腾一整天后终于初步把流程跑通了记录如下 覆盖率监测的原理 Xc ...

  7. iOS自动化探索(一)WebDriverAgent安装

    WebDriverAgent FaceBook推出的一款iOS移动测试框架, 支持真机和模拟器, 同时支持USB, 官方是这样介绍的: https://github.com/facebook/WebD ...

  8. iOS自动化探索(九)使用Jenkins自动化打包并发布iOS App

    继前一篇: Mac环境下安装Jenkins Jenkins安装好后, 我们试着创建一个iOS自动打包并发布的任务 iOS App构建必须在MAC上面使用xcode进行,所以我们要安装下xcode集成插 ...

  9. iOS自动化探索(三)WebDriverAgent Python Client

    之前我们在终端试着调用过WDA API, 今天我们在看一个Python封装的api库 https://github.com/openatx/facebook-wda 安装方式(一): pip inst ...

随机推荐

  1. hdu2597 Simpsons’ Hidden Talents

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目: Simpsons’ Hidden Talents Time Limit: 2000/1000 ...

  2. Loadrunner自带协议分析工具:Protocol Advisor

    录制脚本之前,选对协议很关键,否则错误的协议会导致Virtual User Generator 录制不到脚本,或录制的脚本不完整,有些应用可能需要选择多个协议才能完整的记录 客户端与服务器端的请求. ...

  3. 记一次ZOOKEEPER集群超时问题分析

    CDH安装的ZK,三个节点,基本都是默认配置,一直用得正常,今天出现问题,客户端连接超时6倍时长,默认最大会话超时时间是一分钟.原因分析:1.首先要确认网络正确.确认时钟同步.2.查看现有的配置,基本 ...

  4. Scala快速排序

    Scala 快排 Scala 基本思想:经过一趟排序,把待排对象分成两个独立的部分,一部分的数据大(小)于另一部分,同理,对子对象进行如此处理,以达到所有数据都有序.   package studen ...

  5. Vim - Avoid the escape key

    http://vim.wikia.com/wiki/Avoid_the_escape_key

  6. Safari中的input、textarea无法输入的问题

    原因是这两种表单元素上应用了user-select:none的css属性.一般没人刻意这么做,可能是这样的情况: * { user-select: none; } 在css中排除掉这两种元素就好了: ...

  7. 20145316《Java程序设计》第二周学习总结

    20145316<Java程序设计>第2周学习总结 教材学习内容总结 3.1.1 Java的类型 分为基本类型(Primitive type)和类类型(Class type) 基本类型: ...

  8. netty10---分包粘包

    客户端:根据 长度+数据 方式发送 package com.server; import java.net.Socket; import java.nio.ByteBuffer; public cla ...

  9. 使用selenium前学习HTML(3)——元素

    <!-- HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代码. 注释:开始标签常被称为开放标签(opening tag),结束标签常称为闭合标签(clos ...

  10. 架构私用Nuget服务器

    1.新建一个空的asp.net站点 2.通过nuget引用 Nuget.Server程序集,引用后项目会多出一些文件.修改web.config 里的apikey为你要上传包时用的apikey,我的为: ...