• day12_框架二run_case.py代码


    import os,sys
    BASE_PATH =os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.insert(0, BASE_PATH)
    import unittest,time
    import xmlrunner # 通过pip install xmlrunner安装

    from conf.settings import CASE_PATH, HTML_PATH, XML_PATH, EMAIL_INFO
    from lib.tools import get_new_report, remove_report
    from lib.sendmail_new import SendMail
    from BeautifulReport import BeautifulReport # 把BeautifulReport.zip压缩文件解压到C:Miniconda3Libsite-packages目录下

    user = EMAIL_INFO.get('user') # 从配置文件中获取邮件用户名
    password = EMAIL_INFO.get('password') # 从配置文件中获取邮箱授权码
    host = EMAIL_INFO.get('host') # 从配置文件中获取邮件服务器
    to = EMAIL_INFO.get('to') # 从配置文件中获取邮件接收者
    cc = EMAIL_INFO.get('cc') # 从配置文件中获取抄送邮箱
    subject = EMAIL_INFO.get('subject') # 从配置文件中获取邮件标题
    contents = EMAIL_INFO.get('contents') # 从配置文件中获取邮件内容
    attachments = EMAIL_INFO.get('attachments') # 从配置文件中获取附件


    def html_run():
    suite = unittest.TestSuite()
    all_cases = unittest.defaultTestLoader.discover(CASE_PATH, '*.py')
    for case in all_cases:
    suite.addTest(case)
    # file_name = os.path.join(HTML_PATH,'%s_report.html' % time.strftime('%Y%m%d%H%M%S'))
    # fw = open(file_name,'wb')
    # runner = HTMLTestRunner.HTMLTestRunner(stream = fw,title = '国网电商')
    # runner.run(suite)
    run = BeautifulReport(suite)
    run.report(filename="%s_report.html" % time.strftime('%Y%m%d%H%M%S'), description='金融科技港接口自动化测试报告',
    log_path=HTML_PATH)

    如果想执行某些接口,可以用下面的代码:
    def html_run():
    lis = ('a01*.py', 'a03*.py', 'a05*.py') # 换成list也ok
    suite = unittest.TestSuite()
    for i in lis:
    all_cases = unittest.defaultTestLoader.discover(CASE_PATH, i)
    for case in all_cases:
    suite.addTest(case)

    如果想执行某些接口且函数里有参数,可以用下面的代码:
    
    
    def xml_run():
    suite = unittest.TestSuite()
    all_cases = unittest.defaultTestLoader.discover(CASE_PATH, '*.py')
    for case in all_cases:
    suite.addTest(case)
    runner = xmlrunner.XMLTestRunner(output=XML_PATH)
    runner.run(suite)


    if __name__ == '__main__':
    html_run()
    filename = get_new_report() # 生成最新的报告作为附件
    send = SendMail(user, password, host, to, cc, subject, contents, filename)
    send.send_mail()
    remove_report()
    # xml_run()
  • 相关阅读:
    linux学习笔记----权限与命令之间的关系(极重要)
    linux学习笔记----文件与目录管理
    Linux文件权限与目录配置
    linux:基本命令
    Java:正则表达式
    SDIBT 3237 Boring Counting( 划分树+二分枚举 )
    山东省第四届ACM大学生程序设计竞赛解题报告(部分)
    poj 3522 Slim Span (最小生成树kruskal)
    poj 1236 Network of Schools(又是强连通分量+缩点)
    poj 2762 Going from u to v or from v to u?(强连通分量+缩点重构图+拓扑排序)
  • 原文地址:https://www.cnblogs.com/laosun0204/p/8639596.html
Copyright © 2020-2023  润新知