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

准备测试代码如下:

#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. Winter-1-F Number Sequence 解题报告及测试数据

    Time Limit:1000MS     Memory Limit:32768KB Description ​A number sequence is defined as follows:f(1) ...

  2. spark-sql做ETL时遇到的两个问题

    项目中使用spark-sql来作ETL,遇到两个问题,记录一下. 问题1: spark-sql –master yarn –hiveconf load_date=`date –d ..`  -e 'i ...

  3. iOS 学习 RESTful 中 Http 的幂等性

    一. RESTful  RESTful (Representational State Transfer) 是一种常用流行的软件架构,设计风格或协议标准.提供了一组设计风格和约束条件.主要用于客户端和 ...

  4. ASP.NET MVC BundleConfig介绍和使用

    1.BundleConfig介绍: 在创建ASP.NET MVC5项目时,默认在App_Start文件夹中创建了BudleConfig.cs文件. public class BundleConfig ...

  5. 搭建Firekylin博客

    搭建步骤 1).安装 Node.js curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash - yum - ...

  6. 从页面到服务器,node实现文件下载

    起因: 新来了一个需求,让用户下载一个200m的zip文件,并且校验用户信息,难点:下载的文件是200M的. 现在维护的系统,以前的文件下载,走的是node的静态文件,用的express框架上自带的静 ...

  7. 为什么@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

    Spring Boot会自动根据jar包的依赖来自动配置项目,例如当你项目下面有HSQLDB的依赖,Spring Boot会自动创建默认的内存数据库的数据源DataSource, 但我们使用Mybat ...

  8. 三20135320赵瀚青LINUX内核分析第二周学习笔记

    赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.计算机的三个法宝 存储程 ...

  9. Swift进阶之路(一)——单例模式、属性传值、代理传值、闭包传值

    一.单例模式 单例模式是设计模式中最简单的一种,甚至有些模式大师都不称其为模式,称其为一种实现技巧,因为设计模式讲究对象之间的关系的抽象,而单例模式只有自己一个对象. 关于单例,有三个重要的准则需要牢 ...

  10. Hive表的修改Alter

    1.查看创建表的信息 [show create table] hive> show create table student; OK createtab_stmt CREATE TABLE `s ...