Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

兼容缺陷: v2版本api测试用例的config作用域变量没有被加载 #1137

Open
zhengtong0898 opened this issue Dec 21, 2021 · 0 comments
Assignees
Labels
pending pending for confirmation

Comments

@zhengtong0898
Copy link

zhengtong0898 commented Dec 21, 2021

问题描述

根据下面这个v2版本的api用例,生成出来的.py文件中Config对象加载的不正确.

  1. Config对象加载的是session_variables.name, 期望是加载 config.name.
  2. Config对象并没有加载任何config的成员键值, 期望是加载config中所有成员的键值.
config:
    name: "global variable"
    variables:
        host: "http://127.0.0.1:8888"
        username: "zhangsan"
        password: "zhangsan123"
        status_code: 200
        body_status: 200
        body_msg: "login success"


name: login
request:
    method: POST
    url: "${host}/login"
    headers:
        User-Agent: HttpRunner/${get_httprunner_version()}
        Content-Type: "application/x-www-form-urlencoded"
    data: "username=${username}&password=${password}"
validate:
    - eq: ["status_code", "${status_code}"]
    - eq: ["body.status", "${body_status}"]
    - eq: ["body.msg", "${body_msg}"]

生成出来的.py文件

# NOTE: Generated By HttpRunner v3.1.6
# FROM: testcases/login-api-variables-global.yml


from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase


class TestCaseLoginApiVariablesGlobal(HttpRunner):

    config = Config("login")                       # 这里加载的是不符合预期的name.

    teststeps = [
        Step(
            RunRequest("login")
            .post("${host}/login")
            .with_headers(
                **{
                    "User-Agent": "HttpRunner/${get_httprunner_version()}",
                    "Content-Type": "application/x-www-form-urlencoded",
                }
            )
            .with_data("username=${username}&password=${password}")
            .validate()
            .assert_equal("status_code", "${status_code}")
            .assert_equal("body.status", "${body_status}")
            .assert_equal("body.msg", "${body_msg}")
        ),
    ]


if __name__ == "__main__":
    TestCaseLoginApiVariablesGlobal().test_start()

版本信息

请提供如下版本信息:

  • 操作系统类型: macos
  • Python 版本 3.8
  • HttpRunner 版本 3.1.6
  • 设备 ID: 119394988060799
@zhengtong0898 zhengtong0898 added the pending pending for confirmation label Dec 21, 2021
zhengtong0898 added a commit to zhengtong0898/httprunner that referenced this issue Dec 21, 2021
@zhengtong0898 zhengtong0898 changed the title 对v2 api格式的用例,config加载存在问题 兼容缺陷: v2版本api测试用例的config作用域变量没有被加载 Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending pending for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants