接口测试模板

说明:账号和密码均有破坏,不可复制,粘贴哈
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:UsershuiDesktop est .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