Exemple #1
0
def send_mail(title):
    try:
        server = Server(SMTP_SERVER, PASSWORD, FROM_ADDR)
        if server.connet():
            mail = Mail(server, TO_ADDRS)
            mail.mail_title = title
            mail.mail_content = '股票提醒消息来了'
            mail.send_mail()
        server.close()
        print('mail send out!')
    except Exception as e:
        print(e)
        print('mail send failed!')
Exemple #2
0
    with open(report_path, 'wb') as report:
        runner = HTMLTestRunner(stream=report,
                                title=report_title,
                                description="")
        runner.run(testsuite)
    return report_path


if __name__ == "__main__":
    if testcaseid_list or mixcase_list:
        generate_testcases(testcaseid_list)
        generate_mix_testcase(mixcase_list)
        testsuite = generate_testsuite(testcaseid_list, mixid_list)
        logger.info("【开始执行用例】")
        report_path = run(testsuite)
        logger.info("【结束执行用例】")
        logger.info("")
        flag = int(readconfig.if_send)
        if flag:
            logger.info("【正在发送邮件报告】")
            mail = Mail(readconfig.email_host, readconfig.email_user,
                        readconfig.email_psw)
            content = "自动化测试已结束,请查收测试报告"
            mail.send_mail(readconfig.Receivers, '自动化测试报告', content,
                           report_path)
            logger.info("【邮件报告发送结束】")
            logger.info("")
    else:
        logger.info("缺少用例数据,请指定或者添加相应的用例数据")
        logger.info("")
Exemple #3
0
import unittest
from common.HTMLTestRunner_cn import HTMLTestRunner
import os
import time
from common.mail import Mail

yag = Mail()
case_path = os.path.join(os.getcwd(), 'case')
report_path = os.path.join(os.getcwd(), 'report')


def all_case():
    '''构造待执行的测试用例'''
    discover = unittest.defaultTestLoader.discover(case_path,
                                                   pattern='test*.py')
    print(discover)
    return discover


if __name__ == '__main__':
    now_time = time.strftime('%Y-%m-%d %H_%M_%S')
    filename = os.path.join(report_path, now_time + 'result.html')
    fp = open(filename, 'wb')
    # 执行测试,输出HTML格式的测试报告
    runner = HTMLTestRunner(stream=fp, title='自动化测试报告', description='用例执行情况:')
    runner.run(all_case())
    fp.close()
    yag.send_mail(filename)  #发送邮件