Python BeautifulReport可視化報告代碼實例
操作步驟
1.下載BeautifulReport文件,本例文件下載地址 最新文件下載地址
2.復制文件BeautifulReport,至python安裝Lib\site-packages位置下
3.
3.導入:from BeautifulReport import BeautifulReport import unittest
4.testXXX測試用例函數(shù)下可視化報告用例描述:'''描述,第一個測試用例'''
5.mian下執(zhí)行:
1.實例化:ts = unittest.TestSuite()
2.按類加載全部testxxx測試用例:ts.addTest(unittest.makeSuite(類名))
按函數(shù)加載testxxx測試用例:ts.addTest(類名(‘函數(shù)名'))
3.加載執(zhí)行用例生成報告:result = BeautifulReport(ts)
4.定義報告屬性:result.report(description='XXX報告XX描述', filename= 'xxx.html', log_path='C:\Users\EDZ\eclipse-workspace\pythonTest\Report')
舉例說明
#!/usr/bin/python3
# encoding:utf-8
'''
Created on 2019年9月30日
@author: EDZ
'''
import unittest
from BeautifulReport import BeautifulReport
import os
import time
class HtmlReport(unittest.TestCase):
def test_1(self):
'''描述,第一個測試用例'''
print('test_1錯誤')
self.assertEqual(1, 2)
def test_2(self):
'''描述,第二個測試用例'''
print('test_2正確')
self.assertEqual(1, 1)
def test_3(self):
'''描述,第三個測試用例'''
print('test_3錯誤')
self.assertEqual(2, 3)
if __name__=='__main__':
now = time.strftime("%Y-%m-%d %H%M%S", time.localtime(time.time()))
localpath = os.getcwd()
print('本文件目錄位置:'+localpath)
filepath = os.path.join(localpath,'Report')
print('報告存放路徑 :'+filepath)
ts = unittest.TestSuite()#實例化
#按類加載全部testxxx測試用例
ts.addTest(unittest.makeSuite(HtmlReport))
#按函數(shù)加載testxxx測試用例
#ts.addTest(HtmlReport('test_1'))
filename = now +'.html'
#加載執(zhí)行用例生成報告
result = BeautifulReport(ts)
#定義報告屬性
result.report(description='XXX報告XX描述', filename= filename, log_path=filepath)
控制臺運行結(jié)果
本文件目錄位置:C:\Users\EDZ\eclipse-workspace\pythonTest
報告存放路徑 :C:\Users\EDZ\eclipse-workspace\pythonTest\Report
F.F
測試已全部完成,
可前往C:\Users\EDZ\eclipse-workspace\pythonTest\Report查詢測試報告
可視化報告

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
pymongo為mongodb數(shù)據(jù)庫添加索引的方法
這篇文章主要介紹了pymongo為mongodb數(shù)據(jù)庫添加索引的方法,涉及Python操作mongodb數(shù)據(jù)庫的相關(guān)技巧,非常簡單實用,需要的朋友可以參考下2015-05-05
Python?pandas刪除指定行/列數(shù)據(jù)的方法實例
這篇文章主要給大家介紹了關(guān)于Python?pandas刪除指定行/列數(shù)據(jù)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2022-01-01
從Python的源碼淺要剖析Python的內(nèi)存管理
這篇文章主要介紹了從Python的源碼淺要剖析Python的內(nèi)存管理,需要的朋友可以參考下2015-04-04
Python利用pangu模塊實現(xiàn)文本格式化小工具
其實使用pangu做文本格式標準化的業(yè)務代碼在之前就實現(xiàn)了,主要能夠?qū)⒅形奈谋疚臋n中的文字、標點符號等進行標準化。但是為了方便起來我們這里使用了Qt5將其做成了一個可以操作的頁面應用,需要的可以了解一下2022-10-10

