-
Notifications
You must be signed in to change notification settings - Fork 100
/
run_tests.py
54 lines (46 loc) · 1.7 KB
/
run_tests.py
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
# coding=utf-8
import os
import time
import logging
import pytest
import click
from conftest import REPORT_DIR
from config import RunConfig
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
'''
说明:
1、用例创建原则,测试文件名必须以“test”开头,测试函数必须以“test”开头。
2、运行方式:
> python run_tests.py (回归模式,生成HTML报告)
> python run_tests.py -m debug (调试模式)
'''
def init_env(new_report):
"""
初始化测试报告目录
"""
os.mkdir(new_report)
os.mkdir(new_report + "/image")
@click.command()
@click.option('-m', default=None, help='输入运行模式:run 或 debug.')
def run(m):
if m is None or m == "run":
logger.info("回归模式,开始执行✈✈!")
now_time = time.strftime("%Y_%m_%d_%H_%M_%S")
RunConfig.NEW_REPORT = os.path.join(REPORT_DIR, now_time)
init_env(RunConfig.NEW_REPORT)
html_report = os.path.join(RunConfig.NEW_REPORT, "report.html")
xml_report = os.path.join(RunConfig.NEW_REPORT, "junit-xml.xml")
pytest.main(["-s", "-v", RunConfig.cases_path,
"--html=" + html_report,
"--junit-xml=" + xml_report,
"--self-contained-html",
"--maxfail", RunConfig.max_fail,
"--reruns", RunConfig.rerun])
logger.info("运行结束,生成测试报告♥❤!")
elif m == "debug":
print("debug模式,开始执行!")
pytest.main(["-v", "-s", RunConfig.cases_path])
print("运行结束!!")
if __name__ == '__main__':
run()