apitest/setupMain.py

48 lines
1.5 KiB
Python

# coding:utf-8
import os
import time
import pytest
from config.confManage import dir_manage
from scripts.mkDir import mk_dir
project_path = os.path.split(os.path.realpath(__file__))[0]
if ':' in project_path:
project_path = project_path.replace('\\', '/')
else:
pass
def run():
date = time.strftime('%Y-%m-%d')
localtime = time.strftime('%Y%m%d%H%M%S', time.localtime())
test_case_path = project_path + dir_manage('${test_suite}$') + dir_manage('${case_dir}$') + dir_manage(
'${test_name}$')
# temp地址变量
temp_path = project_path + dir_manage('${report_xml_dir}$') + "temp/" + localtime + '/'
# html地址变量
html_path = project_path + dir_manage('${report_html_dir}$') + date + '/'
# 如果不存在地址路径则创建文件夹
mk_dir(temp_path)
mk_dir(html_path)
# 执行命令行
args = ['-s', '-q', test_case_path, '--alluredir', temp_path]
pytest.main(args)
cmd = 'allure generate %s -o %s -c' % (temp_path, html_path)
os.system(cmd)
# 发送报告
# send_email(localtime + "测试报告", "http://192.168.1.2:9999")
# 钉钉发送
# ding = DingTalkSendMsg()
# ding.send_text("点击链接打开测试报告 http://192.168.1.2:9999",[13688400244])
# 生成html报告
os.system(r'allure generate {0} -o {1} '.format(temp_path, html_path))
# 打开报告服务 并指定端口
os.system(r'allure serve {0} -p 9999'.format(temp_path))
if __name__ == '__main__':
run()