debugtalk.py辅助函数 - 参数化引用debugtalk函数

参数化引用debugtalk函数

  testcase/login_func.yml
config:
    name: 登录用例
    base_url: http://127.0.0.1:端口号
    variables:
        user: test1
        psw: "123456"
    parameters:
        # user: ${get_user()}
        user-psw: ${get_user_psw(3)}
    export:
    - token
teststeps:
-
    name: step-登录
    request:
        method: POST
        url: /api/test/login
        json:
            username: $user
            password: $psw
    extract:
        token: body.token
    validate:
    - eq: [status_code, 200]
    - eq: [body.code, 0]
    - eq: [body.msg, login success!]
    - eq: [body.username, $user]
    - len_eq: [body.token, 40]

  debugtalk.py

def get_user():
    # 只有一个参数时,返回dict格式
    return [
        {"user": "test1"},
        {"user": "test2"},
        {"user": "test3"},
    ]

def get_user_psw(n):
    account = []
    for i in range(1, n+1):
        account.append({"user": 'test%s' % i, "psw": "123456"})
    return account

if __name__ == "__main__":
    print(get_user_psw(3))
posted @ 2022-05-20 15:02  乌醍  阅读(90)  评论(0编辑  收藏  举报