接口测试模板

说明:账号和密码均有破坏,不可复制,粘贴哈
import requests,unittest
import yagmail,time
class loginTest(unittest.TestCase):
def setUp(self):
print("开始")


def test_01(self):
url="https://2.python-requests.org//zh_CN/latest/"
r=requests.get(url)
r.status_code

def tearDown(self):
print("结束")

if __name__=="__main__":
# 没有创建套件,导致不生效
suite=unittest.TestSuite()
import HTMLTestRunner
# report_path=r"C:\Users\hui\Desktop\test\r.html"
#拼接时间
now = time.strftime("%Y-%m-%d %H_%M_%S")
report_path= './'+now+'result.html'


"""
另一种保存文件的方式
with open('html_result', 'w+') as f:
runner = HtmlTestRunner.HTMLTestRunner(output='./', stream=f, report_title='测试报告', descriptions='测试报告详情')
runner.run(suite)
"""

"""
批量加载case的方式
test_dir = './test_case'

discovery = unittest.defaultTestLoader.discover(test_dir, pattern='test*.py')
"""
#发邮件
fp=open(report_path,"wb",)
runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title=u"标题",description=u"描述")
runner.run(suite)
fp.close()
yag = yagmail.SMTP(user='2677989@qq.com', password='gswhabcdidj', host='smtp.qq.com', port='465')
body = "测试进行中"
yag.send(to=['2454760@qq.com'], subject='test 邮件发送', contents=[body, report_path])
print("已发送邮件")

转载于:https://www.cnblogs.com/yanhuidj/p/11270910.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值