Python+request 测试结果结合unittest生成测试报告《四》

测试报告示例图:
     

目录结构介绍:

  

 

主要涉及更改的地方:

  1、导入 Common.HTMLTestRunner2文件

  2、run_test.py文件中新增测试报告相关的代码

 

具体代码实现:

1、run_test.py文件中新增的内容,说明的地方已添加了备注。其余的文件不做任何的更改。具体有什么文件,书写的内容是什么,不太清楚的可以看此链接中的内容:https://www.cnblogs.com/syw20170419/p/10908333.html

#!/usr/bin/env python
# coding=UTF-8

import unittest
from Module.login.login import login
from Module.Todo.Create_todo import todo
from Module.Todo.Todo_report import share_report
import Common.HTMLTestRunner2
import time,os

class run(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_01_login(self):
        '''登录'''
        a = login()
        a.test_login()

    # def test_02_Create_todo(self):
    #     self.todo = todo()
    #     self.todo.test_create_todo()

    def test_03_Todo_report(self):
        '''进入计划报告页面'''
        self.todoreport = share_report()
        self.todoreport.get_share_code()

if __name__ == "__main__":
   # unittest.main()
   now = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
   File_Path = os.getcwd()+ '/Result/Report' + "/"  # 获取到当前文件的目录,并检查是否有report文件夹,如果不存在则自动新建report文件
   print File_Path
   if not os.path.exists(File_Path):
       os.makedirs(File_Path)
   #logging.info(File_Path)
   Report_FileName = file(File_Path + now + r"_ReportResult.html", 'wb')
   print Report_FileName
   runner = Common.HTMLTestRunner2.HTMLTestRunner(stream=Report_FileName, title="接口测试报告",
                                               description="用例执行情况:",verbosity=2)   #verbosity=2:将会取到方法名下的注释内容
   suite = unittest.TestLoader().loadTestsFromTestCase(run)

   runner.run(suite)  ## suite为Case_Gathers.py中的suite,用法:将case中的suite添加到报告中生成

   Report_FileName.close()

 

如上操作完后直接运行,则可看到如上的示例报告中的样式了。

 

转载于:https://www.cnblogs.com/syw20170419/p/10908603.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值