标签:常用 des 客户端浏览器 logs 百度 odi blank code highlight
request的各种方法主要用来处理客户端浏览器提交的请求中的各项参数和选项。如POST,GET最常用的两种请求
官方文档:http://docs.python-requests.org/en/master/user/quickstart/#
安装方法:https://www.cnblogs.com/cheng10/p/9875207.html
unittest:https://docs.python.org/3/library/unittest.html
简单小练习:https://www.cnblogs.com/cheng10/p/10431310.html
HTMLTestRunner配置方法:https://www.cnblogs.com/cheng10/p/10438156.html
开正文,上代码
#导入需要用到的模块
import requests
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
import os
import sys
sys.path.append(‘C:/Users/Desktop/requests_test.py‘)
ABSPATH = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
class MyTest (unittest.TestCase):
#单元测试必须以setUP开头
def setUp(self):
pass
def test_case(self):
self.r = requests.get("https://www.baidu.com")
self.r.status_code
self.r.encoding = ‘utf-8‘
self.r.text
# r.json()
assert self.r.status_code == 200
assert "百度一下" in self.r.text
def tearDown(self):
pass
if __name__=="__main__":
#unittest.main()
suite =unittest.TestSuite()
suite.addTest(MyTest("test_case"))
#定义date日期,time时间
date =time.strftime("%Y%m%d")
time =time.strftime("%Y%m%d-%H%M%S")
#保存报告路径
path ="./report/api"
if not os.path.exists(path):
os.makedirs(path)
else:
pass
report_path =path + time + "report.html"
report_title =u"测试报告"
desc =u"接口自动化测试报告详情"
with open(report_path,‘wb‘) as report:
runner =HTMLTestRunner(stream=report,title=report_title,description=desc)
runner.run(suite)
report.close()
最后结果提醒HTMLTestRunner一定要配置正确
就成功啦
接口框架 python+unittest+request+HTMLTestRunner
标签:常用 des 客户端浏览器 logs 百度 odi blank code highlight
原文地址:https://www.cnblogs.com/cheng10/p/10511177.html