python接口篇-项目实战

01  测试登录接口

import json
import requests
import pytest
from jsonpath import jsonpath

from common.excel import read_excel
from setting.path import case_path

# 从 Excel 当中读取出来所有的用例数据
items = read_excel(case_path, 'adminLogin')

@pytest.mark.parametrize('item', items)
def test_login_02(item):


    url = item.get("url")
    method = item.get("method")
    params = item.get("params", '{}')
    headers = item.get("headers", '{}')
    body = item.get("json", '{}')
    expected = item.get("expected")

    # # 把excel当中字符串转成字典
    # if params is not None:
    #     params_dict = json.loads(params)
    # if headers is not None:
    #     headers_dict = json.loads(headers)
    # body_dict = json.loads(body)
    # 把excel当中字符串转成字典

    params_dict = json.loads(params)
    headers_dict = json.loads(headers)
    body_dict = json.loads(body)

    # 2、发起请求,得到响应
    response = requests.request(url=url,
                              method=method,
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值