sendmsg_test.py
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding:utf-8 -*-
# @Time :2019/12/4 9:37
# @Author :dengyuting
# @File :sendmsg.py
import os
import json
import requests
JENKINS_URL = str(os.getenv("JENKINS_URL"))
BUILD_NUMBER = str(os.getenv("BUILD_NUMBER"))
JOB_NAME = str(os.getenv("JOB_NAME"))
CAUSE = str(os.getenv("CAUSE"))
BUILD_URL = str(os.getenv("BUILD_URL"))
JOB_URL = str(os.getenv("JOB_URL"))
path = os.path.dirname(__file__)
summary_file = os.path.join(path, 'logs','testsuites','task_testsuites.summary.json')
def getresult():
try:
with open(summary_file, 'r', encoding='UTF-8') as f:
f = f.read()
jsonfile = json.loads(f)
if jsonfile["success"] == True:
result = "SUCCESS"
else:
result = "FAIL"
total = jsonfile["stat"]["testcases"]["total"]
success = jsonfile["stat"]["testcases"]["success"]
fail = jsonfile["stat"]["testcases"]["fail"]
duration = round(jsonfile["time"]["duration"])
# teststeps_total = jsonfile["stat"]["teststeps"]["total"]
# teststeps_successes = jsonfile["stat"]["teststeps"]["successes"]
# teststeps_failures = jsonfile["stat"]["teststeps"]["failures"]
# teststeps_errors = jsonfile["stat"]["teststeps"]["errors"]
# teststeps_skipped = jsonfile["stat"]["teststeps"]["skipped"]
return result, total, success, fail, duration
except Exception as err:
print("this is err:{}" .format(err))
def sendinfo():
r =getresult()
data = {}
data['msgtype'] = 'text'
data['text'] = {}
data['text']['content'] = '价值系统项目【mmm_value_api_test】:' \
'\n测试结果:'+r[0]+ \
'\n执行时间:' +str(r[4])+ \
's\n共执行测试用例:' +str(r[1]) +'\nSUCCESS:' +str(r[2])+ '\nFAIL:' +str(r[3])+ \
'\n测试报告地址:http://jenkins.fjmaimaimai.com/view/test/job/mmm_value_api_test/HTML_20Report/'
# data['text']['mentioned_mobile_list'] = ["13559112969","@all"]
# data['text']['content'] = '【opp_api】测试执行结果:' + r[0] + \
# '\n 执行时间:' + str(r[4]) + \
# 's\n TOTAL:' + str(r[1]) + '\n SUCCESS:' + str(r[2]) + '\n FAIL:' + str(r[3])
url = 'https://oapi.dingtalk.com/robot/send?access_token=9a52a7e69fd1bd7cb01e86bf0577af4d74dc15a50f1b17234c50ec2df856021e'
headers = {'Content-Type': 'application/json'}
requests.post(url, json=data, headers=headers)
if __name__ == '__main__':
sendinfo()