-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathconftest.py
More file actions
51 lines (39 loc) · 1.52 KB
/
conftest.py
File metadata and controls
51 lines (39 loc) · 1.52 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
# -*- coding: utf-8 -*-
import time
import pytest
from common.readyaml import ReadYamlData
from base.removefile import remove_file
from common.dingRobot import send_dd_msg
from conf.setting import dd_msg
import warnings
yfd = ReadYamlData()
@pytest.fixture(scope="session", autouse=True)
def clear_extract():
# 禁用HTTPS告警,ResourceWarning
warnings.simplefilter('ignore', ResourceWarning)
yfd.clear_yaml_data()
remove_file("./report/temp", ['json', 'txt', 'attach', 'properties'])
def generate_test_summary(terminalreporter):
"""生成测试结果摘要字符串"""
total = terminalreporter._numcollected
passed = len(terminalreporter.stats.get('passed', []))
failed = len(terminalreporter.stats.get('failed', []))
error = len(terminalreporter.stats.get('error', []))
skipped = len(terminalreporter.stats.get('skipped', []))
duration = time.time() - terminalreporter._sessionstarttime
summary = f"""
自动化测试结果,通知如下,请着重关注测试失败的接口,具体执行结果如下:
测试用例总数:{total}
测试通过数:{passed}
测试失败数:{failed}
错误数量:{error}
跳过执行数量:{skipped}
执行总时长:{duration}
"""
print(summary)
return summary
def pytest_terminal_summary(terminalreporter, exitstatus, config):
"""自动收集pytest框架执行的测试结果并打印摘要信息"""
summary = generate_test_summary(terminalreporter)
if dd_msg:
send_dd_msg(summary)