原代码:
1、首先自定义封装了接口请求类
class InterFaceKey:
#POST请求
def post_method(self,url,data,**kwargs):
return requests.post(url=url,data=data,**kwargs)
#GET请求
def get_method(self,url,data=None,**kwargs):
return requests.get(url=url,params=data,**kwargs)
2、准备的yaml文件格式数据
-
url: http://39.98.138.157:5000/api/login
data:
username: admin
password: '123456'
3、测试代码
@ddt
class SingleInterface(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.keys=InterFaceKey()
@classmethod
def tearDownClass(cls) -> None:
pass
#测试用例
@file_data('../Data/login.yaml')
def test_001_login(self,url,data):
#请求地址url
url=url
#请求参数
# data={
# 'username':'admi