#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/11/14 3:37 PM
# @Author : jiayu.chen
import os
import sys
import unittest
import HTMLTestRunner
import time
sys.path.append(os.path.abspath('..'))
from utils import zip_dir
from conf.sysconfig import doc_path_conf
from utils.send_email import SendMail
# 定义需要执行的用例文件夹
test_dir = doc_path_conf.settle_case_path
# 获取测试套件,pattern参数表示被执行文件的规则
suite = unittest.defaultTestLoader.discover(start_dir=test_dir, pattern='test*.py')
def run():
'''
执行目标文件夹中所有以test开头.py结尾的测试用例
:return:
'''
now = time.strftime('%Y-%m-%d_%H_%M_%S')
reportname = doc_path_conf.report_path + '/' + now + 'SettleSingleTestResult' + '.html' # 定义报告的名称和路径
with open(reportname, 'wb') as f:
runner = HTMLTestRunner.HTMLTestRunner(
stream=f,
title='测试报告',
description='结算系统单功能测试用例'
)
runner.run(suite)
f.close()
# 压缩目标路径中的所有文件到zip包
zip_dir.ZipDir(doc_path_conf.screenshot_path, doc_path_conf.output_path + '/' + now + '_img.zip')
time.sleep(3)
# 发送邮件,设置邮件主题
mail = SendMail(subject="结算系统单功能测试用例")
mail.send()
if __name__ == '__main__':
run()