Commit 8d6e0dc7 authored by 刘丙寅's avatar 刘丙寅

代码优化 - 变更报告模式。新增日志输出以及新增失败重跑三次。

parent d18d9645
......@@ -10,6 +10,7 @@ import sys
import json
import requests
import datetime
from unittestreport import TestRunner
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
......@@ -19,13 +20,6 @@ import sys
reload(sys)
sys.setdefaultencoding('utf8')
'''
# 这个是优化版执行所有用例并发送报告,分四个步骤
# 第一步加载用例
# 第二步执行用例
# 第三步获取最新测试报告
# 第四步发送邮箱 (这一步不想执行的话,可以注释掉最后面那个函数就行)
# 当前脚本所在文件真实路径
cur_path = os.path.dirname(os.path.realpath(__file__))
......@@ -42,7 +36,7 @@ def add_case(caseName="case", rule="case*.py"):
print(discover)
return discover
def run_case(all_case, reportName="report"):
def run_case(all_case):
'''第二步:执行所有的用例, 并把结果写入HTML测试报告'''
# now = time.strftime("%Y_%m_%d_%H_%M_%S")
......@@ -74,12 +68,21 @@ def run_case(all_case, reportName="report"):
#beautiful report 报告页面效果 要将 本地的那个文件夹放到制定的目录下才行。 python里面的 sitepage里面就行
# 怎么放进去: 终端 python3 进入后 import sys 随后 sys.path 最后一个路径 回到终端 open 那个路径。 随后将那个文件夹放进去就行。
# beautiful report 的一套代码
from BeautifulReport import BeautifulReport
# from BeautifulReport import BeautifulReport
#
# runner = BeautifulReport(all_case)
#
# runner.report('更美转诊-接口自动化',filename='更美转诊.html',report_dir='report')
#
# return runner.error_count,runner.failure_count
runner = BeautifulReport(all_case)
runner.report('更美转诊-接口自动化',filename='更美转诊.html',report_dir='report')
runner = TestRunner(all_case,report_dir="report")
res = runner.rerun_run(count=3,interval=2)
error = res.get("error")
fail = res.get("fail")
print(res)
return error, fail
return runner.error_count,runner.failure_count
def get_report_file(report_path):
......@@ -128,7 +131,7 @@ def send_mail(sender, psw, receiver, smtpserver, report_file, port):
# 整体调用流程
if __name__ == "__main__":
all_case = add_case() # 1加载用例
run_case(all_case)
# 生成测试报告的路径
error_count,failure_count = run_case(all_case) # 2执行用例
bug_number = int(error_count) + int(failure_count)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment