python使用HTMLTestRunner導(dǎo)出餅圖分析報(bào)告的方法
目錄如下:

這里有使用
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("用戶名或密碼錯誤", 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'測試報(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)錯的問題
- 解決python3 HTMLTestRunner測試報(bào)告中文亂碼的問題
- python使用 HTMLTestRunner.py生成測試報(bào)告
- Python unittest如何生成HTMLTestRunner模塊
相關(guān)文章
Python獲取CPU、內(nèi)存使用率以及網(wǎng)絡(luò)使用狀態(tài)代碼
這篇文章主要介紹了Python獲取CPU使用率、內(nèi)存使用率、網(wǎng)絡(luò)使用狀態(tài)的相關(guān)代碼,對此有需要的朋友一起測試下。2018-02-02
Python使用pytest-playwright的原因分析
pytest-playwright 是一個(gè) Python 包,它允許您使用 Microsoft 的 Playwright 庫在 Python 項(xiàng)目中進(jìn)行端到端測試,這篇文章主要介紹了Python為什么使用pytest-playwright,需要的朋友可以參考下2023-03-03
Django實(shí)現(xiàn)jquery select2帶搜索的下拉框
最近在開發(fā)一個(gè)web應(yīng)用中需要用到帶搜索功能下拉框,本文實(shí)現(xiàn)Django實(shí)現(xiàn)jquery select2帶搜索的下拉框,感興趣的小伙伴們可以參考一下2021-06-06
淺談Django QuerySet對象(模型.objects)的常用方法
這篇文章主要介紹了淺談Django QuerySet對象(模型.objects)的常用方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
pandas根據(jù)指定條件篩選數(shù)據(jù)的實(shí)現(xiàn)示例
條件篩選是pandas中非常重要的一個(gè)功能,它允許我們根據(jù)特定條件來快速、高效地篩選數(shù)據(jù),本文主要介紹了pandas根據(jù)指定條件篩選數(shù)據(jù)的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
Python學(xué)習(xí)之私有函數(shù),私有變量及封裝詳解
私有函數(shù)與私有變量中的私有就是獨(dú)自擁有、不公開、不分享的意思。放到函數(shù)與變量中就是獨(dú)自擁有的函數(shù)與獨(dú)自擁有的變量,并且不公開。本文將通過示例詳細(xì)講解Python中的私有函數(shù)、私有變量及封裝,感興趣的可以學(xué)習(xí)一下2022-03-03

