day12_框架二run_case.py代码

本文介绍了一种使用Python进行自动化测试的方法,并详细说明了如何生成HTML和XML格式的测试报告,最后通过邮件将最新测试报告发送给指定的收件人。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import os,sys
BASE_PATH = os.path.dirname(os.path.dirname(__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:\Miniconda3\Lib\site-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 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()

转载于:https://www.cnblogs.com/laosun0204/p/8639596.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值