zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    Java :BufferedWriter类和BufferedReader类的构造方法、主要方法
    多线程:四大线程池详解
    多线程:head first Thread.join()
    多线程: 多线程中断机制
    多线程:深入Thread.sleep
    多线程:线程池原理
    java:java构造器和java方法的区别
    java: Java中this和super的用法总结
    postman: 用于网页调试和发送Http请求的chrome插件
    json:JSONObject包的具体使用(JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包)
  • 原文地址:https://www.cnblogs.com/laosun0204/p/8639596.html
Copyright © 2011-2022 走看看