1. 程式人生 > 實用技巧 >Python自動化測試學習(六)— 使用BeautifulReport生成報告

Python自動化測試學習(六)— 使用BeautifulReport生成報告

一、BeautifulReport介紹

1、一個基於unittest模組實現的測試用例報告模板, 可把測試中的結果通過BeautifulReport整合成一個視覺化的報表.

二、引入BeautifulReport

1、可直接從git下載下來ZIP檔案,解壓後直接放到Python安裝路徑下的/ Lib/site-packages目錄下,下載地址 https://github.com/mocobk/BeautifulReport
2、在PyCharm的設定安裝File->Settings->Project Interpreter 搜尋BeautifulReport安裝

三、使用BeautifulReport生成報告
import os
from BeautifulReport import BeautifulReport
"""使用BeautifulReport生成報告"""

# 獲取當前路徑
root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/')
test_suit = unittest.defaultTestLoader.discover("../testcase", 'TestLoginCaseDataDrive.py')
result = BeautifulReport(test_suit)
'''
filename:報告標題
description:報告描述
theme:主題
report_dir:存放路徑
'''
result.report(
    filename="測試報告_demo",
    description="163測試報告",
    theme="theme_default",
    report_dir=root_dir+'\\report_html\\'
)
四、執行結果如下