学习笔记六:生成报告、发送邮件
HTMLTestRunner
下载地址:https://github.com/SeldomQA/HTMLTestRunner
- 下载zip
- 解压
- 在文件夹下,执行安装命令
python setup.py install - pip install yagmail
import unittest
import yagmail
from time import strftime
from TestRunner import HTMLTestRunner
class TestDemo(unittest.TestCase):
"""测试用例说明"""
# 实现发邮件
def send_mail(report_file):
yag = yagmail.SMTP(user="user@qq.com",
password="password", #qq授权配置码:https://blog.csdn.net/mao_hui_fei/article/details/105548814
host='smtp.qq.com')
contents = ['测试结果,请查看附件']
mail_title = "UI自动化测试报告"
send_user = ["user@qq.com"] # 收件人信息
yag.send(send_user, mail_title, contents, report_file)
print("send mail out")
def test_success(self):
"""执行成功"""
self.assertEqual(2 + 3, 5)
@unittest.skip("skip case")
def test_skip(self):
pass
def test_fail(self):
self.assertEqual(5, 6)
def test_error(self):
self.assertEqual(a, 6)
class TestDemo2(unittest.TestCase):
def test_success(self):
self.assertEqual(2 + 2, 4)
class TestDemo3(unittest.TestCase):
def test_fail(self):
self.assertEqual(3, 4)
if __name__ == '__main__':
dicover = unittest.defaultTestLoader.discover('test_*.py')
now_time = strftime("%Y_%m_%d %H_%M_%S")
report_file = './report/' + now_time + '_result.html'
report_name = open(report_file, 'wb')
runner = HTMLTestRunner(stream=report_file,
verbosity=2,
title="百度测试报告",
description="运行环境:win 10,Chrome")
runner.run(dicover)
report_name.close()
TestDemo().send_mail(report_file) # 用例执行完成后,发送邮件

浙公网安备 33010602011771号