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

准备测试代码如下:

  1. #coding: utf-
  2.  
  3. import pytest
  4.  
  5. @pytest.fixture()
  6. def login():
  7. print '输入账号、密码登录'
  8.  
  9. def test_step_1(login):
  10. print '用例步骤1:登录之后其它动作111'
  11.  
  12. def test_step_2(): #不需要登录
  13. print '用例步骤2: 不需要登录, 操作222'
  14.  
  15. def test_step_3(login):
  16. print '用例步骤3:登录之后其它动作333'

生成JunitXML 格式的测试报告

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

执行命令:

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

运行结果:

  1. (wda_python) bash-3.2$ pytest -v test_smtpsimple.py --junitxml=log.xml
  2. ========================================================== test session starts ===========================================================
  3. 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.
  4. cachedir: .pytest_cache
  5. rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
  6. collected items
  7.  
  8. test_smtpsimple.py::test_step_1 PASSED [ %]
  9. test_smtpsimple.py::test_step_2 PASSED [ %]
  10. test_smtpsimple.py::test_step_3 PASSED [%]
  11.  
  12. ---------------------------- generated xml file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.xml ----------------------------
  13. ======================================================== passed in 0.02 seconds ========================================================
  14. (wda_python) bash-3.2$

生存的log.xml:

  1. <?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>输入账号、密码登录
  2. 用例步骤1:登录之后其它动作111
  3. </system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_2" time="0.000802755355835"><system-out>用例步骤2: 不需要登录, 操作222
  4. </system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_3" time="0.00115084648132"><system-out>输入账号、密码登录
  5. 用例步骤3:登录之后其它动作333
  6. </system-out></testcase></testsuite>

生成result log格式的测试报告

  1. (wda_python) bash-3.2$ pytest -s -v test_smtpsimple.py --resultlog=log.txt
  2. ========================================================== test session starts ===========================================================
  3. 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.
  4. cachedir: .pytest_cache
  5. rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
  6. collected items
  7.  
  8. test_smtpsimple.py::test_step_1 输入账号、密码登录
  9. 用例步骤1:登录之后其它动作111
  10. PASSED
  11. test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
  12. PASSED
  13. test_smtpsimple.py::test_step_3 输入账号、密码登录
  14. 用例步骤3:登录之后其它动作333
  15. PASSED
  16.  
  17. ============================================================ warnings summary ============================================================
  18. /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/lib/python2./site-packages/_pytest/resultlog.py:
  19. /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.
  20. See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information.
  21. _issue_warning_captured(RESULT_LOG, config.hook, stacklevel=)
  22.  
  23. -- Docs: https://docs.pytest.org/en/latest/warnings.html
  24. ================================================== passed, warnings in 0.01 seconds ==================================================
  25. (wda_python) bash-3.2$

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

  1. . test_smtpsimple.py::test_step_1
  2. . test_smtpsimple.py::test_step_2
  3. . test_smtpsimple.py::test_step_3

可以改成这样:

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

生存的log.txt为

  1. ============================= test session starts ==============================
  2. 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.
  3. cachedir: .pytest_cache
  4. rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
  5. collecting ... collected items
  6.  
  7. test_smtpsimple.py::test_step_1 输入账号、密码登录
  8. 用例步骤1:登录之后其它动作111
  9. PASSED
  10. test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
  11. PASSED
  12. test_smtpsimple.py::test_step_3 输入账号、密码登录
  13. 用例步骤3:登录之后其它动作333
  14. PASSED
  15.  
  16. =========================== passed in 0.01 seconds ===========================

生成Html格式的测试报告

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

  1. pip install pytest-html

使用指令:

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

运行结果:

  1. (wda_python) bash-3.2$ pytest -s -v test_smtpsimple.py --html=log.html
  2. ========================================================== test session starts ===========================================================
  3. 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.
  4. cachedir: .pytest_cache
  5. 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'}}
  6. rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
  7. plugins: metadata-1.8., html-1.20.
  8. collected items
  9.  
  10. test_smtpsimple.py::test_step_1 输入账号、密码登录
  11. 用例步骤1:登录之后其它动作111
  12. PASSED
  13. test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
  14. PASSED
  15. test_smtpsimple.py::test_step_3 输入账号、密码登录
  16. 用例步骤3:登录之后其它动作333
  17. PASSED
  18.  
  19. --------------------------- generated html file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.html ---------------------------
  20. ======================================================== passed in 0.03 seconds ========================================================
  21. (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. cisco anyconnect linux

    cisco anyconnect linux 官方的下载需要登录验证,比较麻烦,可以从这个地方直接下载使用.支持ubuntu,centos. cisco anyconnect vpn client我本 ...

  2. android解决setOnItemClickListener没有响应

    今天遇到一种情况,抽屉式导航栏里的listView的点击事件没有响应点击事件. 查看了下,原来是因为抽屉式导航栏的fragment声明,放在了内容fragment之前,导致点击动作被内容fragmen ...

  3. MVP架构学习

    MVP架构学习 M:数据层(数据库,文件,网络等...) V:UI层(Activity,Fragment,View以及子类,Adapter以及子类) P:中介,关联UI层和数据层,因为V和M是相互看不 ...

  4. C#数组的Map、Filter、Reduce操作

    在Javascript.Python等语言里,Map.Filter和Reduce是数组的常用方法,可以让你在实现一些数组操作时告别循环,具有很高的实用价值.它们三个的意义大家应该都清楚,有一个十分形象 ...

  5. Ubuntu 16.04 安装Postman

    Ubuntu 16.04 安装Postman: 1.官网下载地址:https://www.getpostman.com/根据机器类型选择64位下载. 2.进入下载目录,解压该文件sudo tar -x ...

  6. Javascript中的函数数学运算

    1.Math函数与属性使用语法 Math.方法名(参数1,参数2,...); Math.属性; 说明 Math函数可以没有参数,比如Math.random()函数,或有多个参数,比如Math.max( ...

  7. C++之图片旋转90,再保存

    下面测试代码只需要全部放在一个.cpp文件里就行 //#include "stdafx.h"#include <stdio.h>#include <string& ...

  8. 20145314郑凯杰《信息安全系统设计基础》第6周学习总结 part A

    第4章 处理器体系结构 part 1 本部分对改章节的知识点进行总结: 一个处理器支持的指令和指令的字节级编码称为它的指令集体系结构(ISA). 不同的出路器有不同的ISA. ISA模型看上去应该是顺 ...

  9. SpringMVC,针对不支持PUT、DELETE提交的游览器处理方式

    在REST服务中必不可少的需要PUT.DELETE提交,但是目前很多的游览器并不支持.所以在使用REST前需要进行一些额外的处理. 具体解决方案如下: 1,先添加一个filter.这个filter就是 ...

  10. Juniper SRX 简单命令二

    --------------------------Juniper SRX 用户管理--------------------------- Juniper的命令,其实是比较形象的,英文稍微好一点,基本 ...