python习题#讲解13参数化讲解python+requests+pytest接口自动化

1.先了解项目目录架构

        测试框架
       目录结构
       python package类文件夹:1.api        2.scripts        3.common
       directory类文件夹:1.data        2.report
       项目根目录文件:1.config.py        2.pytest.ini

2.参数化步骤

1)api文件夹中封装登录.py

#登录
import requests#导包
class Ihrmlogin(object):#封装登录类
    @classmethod#类方法
    def login(cls,json):#封装登录方法
        rep= requests.post("http://ihrm-test.itheima.net/api/sys/login",json= json)
        return rep#发送登录请求返回登录数据

2)data文件夹中放参数化数据.json

[
  {
    "desc": "登陆成功",
    "req_data": {
      "mobile": "13800000002",
      "password": "123456"
    },
    "status_code": 200,
    "success": true,
    "code": 10000,
    "message": "操作成功"
  },
  {
    "desc": "手机号未注册",
    "req_data": {
      "mobile": "11777771111",
      "password": "123456"
    },
    "status_code": 200,
    "success": false,
    "code": 20001,
    "message": "用户名或密码错误"
  },
  {
    "desc": "密码错误",
    "req_data": {
      "mobile": "13800000002",
      "password": "12345678"
    },
    "status_code": 200,
    "success": false,
    "code": 20001,
    "message": "用户名或密码错误"
  },
  {
    "desc": "多参",
    "req_data": {
      "mobile": "13800000002",
      "password": "123456",
      "abc": "123"
    },
    "status_code": 200,
    "success": true,
    "code": 10000,
    "message": "操作成功"
  },
  {
    "desc": "少参",
    "req_data": {
      "mobile": "13800000002"
    },
    "status_code": 200,
    "success": false,
    "code": 20001,
    "message": "用户名或密码错误"
  },
  {
    "desc": "无参",
    "req_data": null,
    "status_code": 200,
    "success": false,
    "code": 99999,
    "message": "系统繁忙"
  }
]

2.1)data文件夹中也可以用w写入json数据.py

# my_list = [{"d

你可能感兴趣的:(python,python,开发语言,json)