def login_user(): email = request.form['email'] password = request.form['password'] if User.login_valid(email, password): User.login(email) send_email.send_email(session['email']) else: session['email'] = None return render_template('profile.html', email=session['email'])
def send_mail(subject, report_file, file_names): # 读取测试报告内容,作为邮件的正文内容 with open(report_file, "rb") as f: mail_body = f.read() send_email(subject, mail_body, file_names)
from common.config import conf from common.send_email import send_email # 读取测试报告存放的文件名 file_name = conf.get('report', 'file_name') # 获取当前时间 file_name = time.strftime("%Y%m%d%H%M%S", time.localtime()) + file_name # 创建一个测试集合 suite = unittest.TestSuite() # 创建loader对象 loader = unittest.TestLoader() # 添加测试用例 suite.addTest(loader.discover(CASE_DIR)) filepath = os.path.join(REPORT_DIR, file_name) # 执行测试用例生成测试报告 with open(filepath, 'wb') as f: runner = HTMLTestRunner(stream=f, verbosity=2, title='接口测试报告', description='测试报告', tester='shier') runner.run(suite) # 发送测试报告到邮箱 send_email(filepath)
''' 定义测试报告的地址 ''' htmlreport = reportPath + '\\' + r'%s_test_report.html' % now #print(htmlreport) with open(htmlreport, 'wb') as f: HTMLTestReportCN.HTMLTestRunner(stream=f, verbosity=2, title='parcels接口冒烟测试报告', description='用例执行情况').run(all_case) #xmlrunner.XMLTestRunner(output=reportPath).run(all_case)配合jenkins使用时得生成xml文佳 if __name__ == '__main__': # -v,-q,-s,分别是pytest框架带的参数 #-v,详细输出 #-q,简单输出 #-s, 输出日志 #pytest.main(['-v','-s','./test_case/test_case.py','--html=report/{}_report.html'.format(now) ]) all_case = add_case() #添加测试用例 run_case(all_case) #执行测试用例 #发送测试报告 report = new_report(report_path) try: send_email(report) print('邮件已发送!请查收') except smtplib.SMTPException as Error: print("jenkisn") print("0001") print(Error.decode('UTF-8')) print("Error:邮件发送失败")
# list that test cases that need to run alltestcases = cases_list_ko.case_list() testunit = unittest.TestSuite() # add cases to suite print "start to run test cases...." for test in alltestcases: testunit.addTest(unittest.makeSuite(test)) print test now = time.strftime("%Y-%m-%d_%H_%M_%S") filename = folder + now + "_" + OS + OS_VERSION + "_" + BROWSER + "_" + str( BROWSER_VERSION) + '_Test_Report.html' fp = open(filename, 'w') runner = HTMLTestRunner.HTMLTestRunner( stream=fp, title=OS + OS_VERSION + "_" + BROWSER + "_" + str(BROWSER_VERSION) + '_Smoke Test Result', description='Please see attachment for more details') runner.run(testunit) print "Writing Report" fp.close() #send email send_email.send_email(HOST, PORT, mail_username, mail_password, to_addrs, folder)
#设置测试用例、测试报告路径 test_dir='../test_case_business' report_dir='../reports' logger.info('start run test case...') #加载测试用例 suite = unittest.TestSuite() # suite.addTest(unittest.makeSuite(test_appDemand.TestAppDemand)) # suite.addTest(unittest.makeSuite(test_processingDemand.TestprocessingDemand)) suite.addTest(unittest.makeSuite(test_processing_order_xq.TestprocessingOderXq)) suite.addTest(unittest.makeSuite(test_booking.TestBooking)) # suite.addTest(unittest.makeSuite(test_processing_order_booking.TestprocessingOder)) # suite.addTest(unittest.makeSuite(test_check.TestCheck)) ##设置测试报告名称 now=time.strftime('%Y-%m-%d %H_%M_%S') report_name=report_dir+'/'+now+'report.html' #执行测试用例生成测试报告 with open(report_name,'wb') as file: HTMLTestRunner(stream=file,title='社会化服务测试报告',description='社会化服务测试报告',retry=1,save_last_try=False).run(suite) # 通过邮件发送测试报告的 logger.info("start send email......") try: rep = send_email.get_report('../reports') send_email.send_email(rep) except: logger.error("send_email failed") finally: logger.info("send_email success")
============================ Author:柠檬班-木森 Time:2020/3/17 20:18 E-mail:[email protected] Company:湖南零檬信息技术有限公司 ============================ """ import unittest from BeautifulReport import BeautifulReport from common.handle_logging import log from common.handle_path import CASE_DIR, REPORT_DIR from common.send_email import send_email log.info("---------------开始执行测试用例-----------------------") # 创建测试套件 suite = unittest.TestSuite() # 加载用例到套件 loader = unittest.TestLoader() suite.addTest(loader.discover(CASE_DIR)) # 执行用例生成报告 bf = BeautifulReport(suite) bf.report("注册接口", filename="report.html", report_dir=REPORT_DIR) log.info("---------------测试用例执行完毕-----------------------") send_email()
suite = unittest.TestSuite() loader = unittest.TestLoader() suite.addTest(loader.loadTestsFromTestCase(LoginTestCase)) #suite.addTests(loader.) now = time.strftime("%Y-%m-%d_%H_%M_%S") file = os.path.join(REPORT_DIR, now) filename = ("{}.html".format(file)) with open(filename, "wb") as f: runner = HTMLTestRunner(stream=f, verbosity=2, title="测试报告", description="18期测试报告", tester="liumei") runner.run(suite) send_email(filename) # 创建一个测试集合 #suite = unittest.TestSuite() # 添加测试用例 # 第一种 单个用例添加 :接收的参数时测试用例对象 # suite.addTest(LoginTestCase('test_login')) # suite.addTest(LoginTestCase('test_password_error')) # suite.addTest(LoginTestCase('test_password_lt6')) # 第二种:一次添加多条 # suite.addTests([LoginTestCase('test_login'),LoginTestCase('test_login'),LoginTestCase('test_login')]) # 第三种:一次添加一个测试用例类(类名不需要加引号) # loader = unittest.TestLoader()
from config.config import * """整合用例""" # suite = unittest.TestSuite() # suite.addTest(TestCase('test_get_test019')) suite = unittest.TestLoader().loadTestsFromTestCase(TestCase) """执行用例""" if send_email_switch: file = open(report_dir, 'wb') # 二进制写格式打开要生成的报告文件 HTMLTestRunner(stream = file,title = "",description="", tester="autoBuild").run(suite) file.close() else: unittest.TextTestRunner(verbosity = 2).run(suite) """发送邮件""" if send_email_switch: send_email(report_dir,email_receiver)
File : run_test.py ============================ """ import os import unittest from common.contains import CASEDIR, REPORTDIR from library.HTMLTestRunnerNew import HTMLTestRunner from testcases import test_main_stream from common.send_email import send_email report_path = os.path.join(REPORTDIR, 'report.html') # 一、创建测试套件 suite = unittest.TestSuite() # 二、加载测试用例到测试套件中 loader = unittest.TestLoader() # suite.addTest(loader.loadTestsFromModule(test_main_stream)) suite.addTest(loader.discover(CASEDIR)) # 三、创建一个测试运行程序启动器 runner = HTMLTestRunner(stream=open(report_path, 'wb'), title='练习unittest', description='练习unittest', tester='dxl') # 四、使用启动器执行测试套件 runner.run(suite) # 发送邮件 send_email(report_path)
# -*- coding: utf-8 -*- # @Author : leizi from case.example_test_api import Test_api import unittest, time, os from common import BSTestRunner from common import send_email if __name__ == '__main__': suite = unittest.TestSuite() suite.addTests(unittest.TestLoader().loadTestsFromTestCase(Test_api)) now = time.strftime('%Y-%m%d', time.localtime(time.time())) basedir = os.path.abspath(os.path.dirname(__file__)) file_dir = os.path.join(basedir, 'report') file = os.path.join(file_dir, (now + '.html')) re_open = open(file, 'wb') runner = BSTestRunner.BSTestRunner(stream=re_open, title='接口测试报告', description='测试结果') m = runner.run(suite) send_email.send_email(receiver=['gaoxin', '*****@*****.**'], file_path=file)