python使用HTMLTestRunner導(dǎo)出餅圖分析報(bào)告的方法
更新時(shí)間:2019年12月30日 15:34:52 作者:春天的菠菜
這篇文章主要介紹了python使用HTMLTestRunner導(dǎo)出餅圖分析報(bào)告的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
目錄如下:
這里有使用
HTMLTestRunner和 echarts.common.min.js文件[見百度網(wǎng)盤,這里給自己留個(gè)記錄便于查詢]
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("用戶名或密碼錯(cuò)誤", 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("用戶名或密碼錯(cuò)誤", 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'測試報(bào)告', description=u'用例執(zhí)行情況') runner.run(test) file_result.close()
運(yùn)行產(chǎn)生報(bào)告查看報(bào)告:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Python HTMLTestRunner如何下載生成報(bào)告
- Python HTMLTestRunner測試報(bào)告view按鈕失效解決方案
- Python HTMLTestRunner庫安裝過程解析
- Python HTMLTestRunner可視化報(bào)告實(shí)現(xiàn)過程解析
- 詳解python3中用HTMLTestRunner.py報(bào)ImportError: No module named ''StringIO''如何解決
- 解決python3運(yùn)行selenium下HTMLTestRunner報(bào)錯(cuò)的問題
- 解決python3 HTMLTestRunner測試報(bào)告中文亂碼的問題
- python使用 HTMLTestRunner.py生成測試報(bào)告
- Python unittest如何生成HTMLTestRunner模塊
相關(guān)文章
Python Django框架介紹之模板標(biāo)簽及模板的繼承
今天給大家?guī)鞵ython Django框架的相關(guān)知識(shí),文中對模板標(biāo)簽及模板的繼承介紹的非常詳細(xì),對正在學(xué)習(xí)python的小伙伴們有很好地幫助,需要的朋友可以參考下2021-05-05學(xué)生如何注冊Pycharm專業(yè)版以及pycharm的安裝
這篇文章主要介紹了學(xué)生如何注冊Pycharm專業(yè)版以及pycharm的安裝,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Python序列化與反序列化相關(guān)知識(shí)總結(jié)
今天給大家?guī)黻P(guān)于python的相關(guān)知識(shí),文章圍繞著Python序列化與反序列展開,文中有非常詳細(xì)的介紹,需要的朋友可以參考下2021-06-06