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()
复制代码

 

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

 

posted @   Syw_文  阅读(428)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2017-05-22 MYSQL—— 完整性约束条件中primary key、auto_increment使用总结!
2017-05-22 MYSQL—— year类型的使用与注意点!
点击右上角即可分享
微信分享提示