python使用HTMLTestRunner導出餅圖分析報告的方法
更新時間:2019年12月30日 15:34:52 作者:春天的菠菜
這篇文章主要介紹了python使用HTMLTestRunner導出餅圖分析報告的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
目錄如下:
這里有使用
HTMLTestRunner和 echarts.common.min.js文件[見百度網盤,這里給自己留個記錄便于查詢]
unit_test.py代碼如下:
import unittest import requests import time import os.path from common import HTMLTestRunner class TestLogin(unittest.TestCase): def setUp(self): # 獲取session對象 self.session = requests.session() # 登錄url self.url = 'http://XXXXXX/oauth/oauth/token' def test_login_success(self): data = { 'grant_type': 'password', 'username': 'iu', 'password': '111', 'client_id': 'web', 'client_secret': 'web-secret' } r = self.session.post(url=self.url, data=data) try: self.assertEqual(r.json()['token_type']) except AssertionError as e: print(e) def test_username_not_exit(self): data = { 'grant_type': 'password', 'username': '322u', 'password': '8', 'client_id': 'web', 'client_secret': 'web-secret' } r = self.session.post(url=self.url, data=data) try: self.assertEqual("用戶名或密碼錯誤", r.json()["error_description"]) except AssertionError as e: print(e) def test_password_error(self): data = { 'grant_type': 'password', 'username': '2u', 'password': '888ssss888', 'client_id': 'web', 'client_secret': 'web-secret' } r = self.session.post(url=self.url, data=data) try: self.assertEqual("用戶名或密碼錯誤", r.json()["error_description"]) except AssertionError as e: print(e) def tearDown(self): self.session.close() if __name__ == '__main__': # unittest.main() test = unittest.TestSuite() test.addTest(TestLogin('test_login_success')) test.addTest(TestLogin('test_username_not_exit')) test.addTest(TestLogin('test_password_error')) rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time())) file_path = os.path.abspath('.') + '\\report\\' + rq + '-result.html' file_result = open(file_path, 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=file_result, title=u'測試報告', description=u'用例執(zhí)行情況') runner.run(test) file_result.close()
運行產生報告查看報告:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Python HTMLTestRunner如何下載生成報告
- Python HTMLTestRunner測試報告view按鈕失效解決方案
- Python HTMLTestRunner庫安裝過程解析
- Python HTMLTestRunner可視化報告實現(xiàn)過程解析
- 詳解python3中用HTMLTestRunner.py報ImportError: No module named ''StringIO''如何解決
- 解決python3運行selenium下HTMLTestRunner報錯的問題
- 解決python3 HTMLTestRunner測試報告中文亂碼的問題
- python使用 HTMLTestRunner.py生成測試報告
- Python unittest如何生成HTMLTestRunner模塊
相關文章
學生如何注冊Pycharm專業(yè)版以及pycharm的安裝
這篇文章主要介紹了學生如何注冊Pycharm專業(yè)版以及pycharm的安裝,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-09-09