增加依赖用例处理,调整部分代码

This commit is contained in:
lileilei
2022-01-16 11:07:30 +08:00
parent a026cda2fe
commit fe2320dbe7
18 changed files with 165 additions and 465 deletions

View File

@@ -99,6 +99,7 @@ import os
import sys, copy
from io import StringIO as StringIO
# ------------------------------------------------------------------------
# The redirectors below are used to capture output during testing. Output
# sent to sys.stdout and sys.stderr are automatically captured. However
@@ -278,7 +279,7 @@ class Template_mixin(object):
<p class='description'>%(description)s</p>
</div> </div >
"""
HEADING_TMPL_New="""
HEADING_TMPL_New = """
<div class='heading'>
<div style='width: 50%%;float:left;margin-top:inherit'>
<h1>%(title)s</h1>
@@ -388,7 +389,7 @@ class Template_mixin(object):
#
ENDING_TMPL = """<div id='ending'>&nbsp;</div>"""
SCRPICTold="""
SCRPICTold = """
<script language='javascript' type='text/javascript'>
output_list = Array();
@@ -468,8 +469,7 @@ function html_escape(s) {
</html>
"""
SCRPICTDATA=r"""
SCRPICTDATA = r"""
<script language='javascript' type='text/javascript'>
var dom = document.getElementById('containerchart');
var myChart = echarts.init(dom);
@@ -608,10 +608,14 @@ function html_escape(s) {
</body>
</html>
"""
# -------------------- The end of the Template class -------------------
TestResult = unittest.TestResult
class MyResult(TestResult):
def __init__(self, verbosity=1, trynum=1):
# 默认次数是0
@@ -714,7 +718,6 @@ class MyResult(TestResult):
pass
class _TestResult(MyResult):
# note: _TestResult is a pure representation of results.
# It lacks the output and reporting ability compares to unittest._TextTestResult.
@@ -738,8 +741,8 @@ class BSTestRunner(Template_mixin):
self.stream = stream
self.verbosity = verbosity
self.trynum = trynum
self.is_show=is_show
self.filepath=filepath
self.is_show = is_show
self.filepath = filepath
if title is None:
self.title = self.DEFAULT_TITLE
else:
@@ -760,9 +763,10 @@ class BSTestRunner(Template_mixin):
pass
self.stopTime = datetime.datetime.now()
if self.is_show:
name=os.path.join(self.filepath,self.stopTime.strftime('%Y_%m_%d_%H_%M_%S')+'.txt')
with open(name,'w+') as f:
f.write(result.success_count.__str__()+"_"+result.error_count.__str__()+"_"+result.failure_count.__str__())
name = os.path.join(self.filepath, self.stopTime.strftime('%Y_%m_%d_%H_%M_%S') + '.txt')
with open(name, 'w+') as f:
f.write(
result.success_count.__str__() + "_" + result.error_count.__str__() + "_" + result.failure_count.__str__())
f.close()
self.generateReport(test, result)
print('\n测试耗时: %s' % (self.stopTime - self.startTime))
@@ -814,9 +818,9 @@ class BSTestRunner(Template_mixin):
report = self._generate_report(result)
ending = self._generate_ending()
if self.is_show:
scrpit=self.___generate_scrpitone()
scrpit = self.___generate_scrpitone()
else:
scrpit=self._generate_scrpit()
scrpit = self._generate_scrpit()
output = self.HTML_TMPL % dict(
title=saxutils.escape(self.title),
generator=generator,
@@ -832,7 +836,7 @@ class BSTestRunner(Template_mixin):
return self.STYLESHEET_TMPL
def _generate_heading(self, report_attrs):
ISSHOWPERDATA=True
ISSHOWPERDATA = True
if ISSHOWPERDATA:
a_lines = []
for name, value in report_attrs:
@@ -845,7 +849,8 @@ class BSTestRunner(Template_mixin):
a_lines.append(line)
if self.is_show:
heading = self.HEADING_TMPL_New % dict(
title=saxutils.escape(self.title),parameters=''.join(a_lines),description=saxutils.escape(self.description),)
title=saxutils.escape(self.title), parameters=''.join(a_lines),
description=saxutils.escape(self.description), )
else:
heading = self.HEADING_TMPL % dict(
title=saxutils.escape(self.title),
@@ -959,27 +964,30 @@ class BSTestRunner(Template_mixin):
def _generate_ending(self):
return self.ENDING_TMPL
def ___generate_scrpitone(self):
namerun,faillist,success,error=self._readresult()
return self.SCRPICTDATA% dict(reslutname=namerun,
success=success,
fail=faillist,
error=error)
def _readresult(self):
namerun=[]
faillist=[]
success=[]
error=[]
for root,dirs,files in os.walk(self.filepath):
namerun, faillist, success, error = self._readresult()
return self.SCRPICTDATA % dict(reslutname=namerun,
success=success,
fail=faillist,
error=error)
def _readresult(self):
namerun = []
faillist = []
success = []
error = []
for root, dirs, files in os.walk(self.filepath):
for file in files:
if file.endswith(".txt"):
namerun.append(file.split(".")[0].split("/")[-1])
with open(os.path.join(root,file),'r') as f:
reslut=f.readline().split('\n')[0].split("_")
with open(os.path.join(root, file), 'r') as f:
reslut = f.readline().split('\n')[0].split("_")
success.append(reslut[0])
error.append(reslut[1])
faillist.append(reslut[2])
return namerun,faillist,success,error
return namerun, faillist, success, error
def _generate_scrpit(self):
return self.SCRPICTold
@@ -1011,5 +1019,3 @@ main = TestProgram
##############################################################################
# Executing this module from the command line
##############################################################################

View File

@@ -5,7 +5,7 @@
"""
'''封装钉钉群发消息'''
import requests, json
from config.config_T import Dingtalk_access_token
from config.config import Dingtalk_access_token
def send_ding(content):

View File

@@ -2,15 +2,15 @@
# @Author : leizi
import smtplib, time, os
from email.mime.text import MIMEText
from email.utils import formataddr, parseaddr
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
import yaml
def load_emil_setting(): # 从配置文件中加载获取email的相关信息
import yaml
data_file = open(r".\\config\\email.yaml", "r")
datas = yaml.load(data_file)
filepath = os.path.join(os.path.join(os.getcwd(), 'config'), 'email.yaml')
data_file = open(filepath, "r")
datas = yaml.load(data_file, Loader=yaml.FullLoader)
data_file.close()
return (datas['foremail'], datas['password'], datas['toeamil'], datas['title'])

View File

@@ -2,7 +2,7 @@
# @Time : 2017/6/4 20:35
# @Author : lileilei
# @File : get_excel.py
import xlrd,os
import xlrd, os
from Public.log import LOG, logger
@@ -33,13 +33,19 @@ def datacel(filepath):
print(e)
LOG.info('打开测试用例失败,原因是:%s' % e)
return
@logger('生成数据驱动所用数据')
def makedata():
path = os.path.join(os.path.join(os.getcwd(),'test_case_data'),'case.xlsx')
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname=datacel(path)
i=0
make_data=[]
path = os.path.join(os.path.join(os.getcwd(), 'test_case_data'), 'case.xlsx')
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel(path)
make_data = []
for i in range(len(listid)):
make_data.append({'url':listurl[i],'key':listkey[i],'coneent':listconeent[i],'fangshi':listfangshi[i],'qiwang':listqiwang[i]})
i+=1
make_data.append({'url': listurl[i], 'key': listkey[i],
'coneent': listconeent[i], 'fangshi': listfangshi[i],
'qiwang': listqiwang[i],
'id': listid[i]},
)
i += 1
return make_data

View File

@@ -4,7 +4,6 @@
@file: py_Html.py
@time: 2017/6/5 17:04
"""
import os
titles = '接口测试'

View File

@@ -4,7 +4,7 @@
@file: pyreport_excel.py
@time: 2017/6/7 8:47
"""
import xlrd, os, xlwt, yaml, xlsxwriter # 导入库
import os, xlwt, yaml
from xlwt import *
@@ -56,9 +56,8 @@ def yangshique(me):
def create(filename, list_pass, list_fail, listids, listnames, listkeys, listconeents, listurls, listfangshis,
listqiwangs, list_json, listrelust):
filepath = open( os.path.join(os.path.join(os.getcwd(),'config'),'test_report.yaml'), encoding='utf-8')
file_config = yaml.load(filepath,Loader=yaml.FullLoader)
filepath = open(os.path.join(os.path.join(os.getcwd(), 'config'), 'test_report.yaml'), encoding='utf-8')
file_config = yaml.load(filepath, Loader=yaml.FullLoader)
file = Workbook(filename)
table = file.add_sheet('测试结果', cell_overwrite_ok=True)
style = yangshi1()

View File

@@ -1 +1 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-