Python Pytest自动化测试框架 生成测试报告

Time will tell.

本章节来说说如何生成测试报告准备测试代码如下:

#coding: utf-8

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.15, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.7
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected 3 items                                                                                                                        

test_smtpsimple.py::test_step_1 PASSED                                                                                             [ 33%]
test_smtpsimple.py::test_step_2 PASSED                                                                                             [ 66%]
test_smtpsimple.py::test_step_3 PASSED                                                                                             [100%]

---------------------------- generated xml file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.xml -----------------
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值