python学习之路_接口参数化2

python接口参数化2

使用@pytest.mark.parametrize进行参数化

代码

import requests
import pytest
#使用这个装饰器,作用类似于需要参数化几个参数,就在括号中写入几个参数,并写入值
@pytest.mark.parametrize('username,password',[{'李白1211','123456'},{'李白113','123456'},{'李白141','123456'}])
class Test_no1():
    def test_learn1(self,username,password):
        url = "http://localhost:8080/admin/register"
        body = {
            "email": "string",
            "icon": "string",
            "nickName": "string",
            "note": "string",
            "password": "12112",
            "username": "11212"
        }
        改值
        body["username"]=username
        body["password"]=password
        #发送请求
        r1=requests.post(url=url,json=body)
        print(r1.text)
        #断言
        assert r1.json()["message"] == "操作成功"

响应代码

test_222.py .{"code":200,"message":"操作成功","data":null}
.{"code":200,"message":"操作成功","data":null}
.{"code":200,"message":"操作成功","data":null}

你可能感兴趣的:(python学习之路_接口参数化2)