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

validate自定义函数校验失败时,report内容缺失 #1717

Open
jonzha9527 opened this issue Dec 11, 2023 · 0 comments
Open

validate自定义函数校验失败时,report内容缺失 #1717

jonzha9527 opened this issue Dec 11, 2023 · 0 comments
Labels
pending pending for confirmation

Comments

@jonzha9527
Copy link

validate如果包含自定义函数,当他验证失败后,生成的report 中record 为空

validate中需要验证自定义函数的结果,此函数只会返回true/false
当函数返回和预期一致时,report 内容正常,validate 信息都有
当函数返回和预期不一致,即 validate fail 的情况,report 中信息缺失,而且step 计算有误

版本信息

        "httprunner_version": "3.1.11",
        "python_version": "CPython 3.9.17",
        "platform": "Linux-3.10.0-1160.95.1.el7.x86_64-x86_64-with-glibc2.17"

用例

config:
    base_url: https://yapi.uihcloud.cn/mock/375
    name: case-list

teststeps:
    -   name: hook test
        variables:
            page: 1
            num1: 5
            num2: 12
        request:
            method: GET
            params:
                page: $page
                project: 11
            url: /testcase/
        validate:
            -   eq: ["${compare_nums($num1, $num2)}", false]
            -   gt: ["body.results[0].id", 10]

函数

def compare_nums(a, b):
    return a > b

CMD

hrun cases/validate.yml --disable-warnings --save-tests

report

validate success

            "records": [
                {
                    "success": true,
                    "name": "hook test",
                    "data": {
                        "success": true,
                        "validators": {
                            "validate_extractor": [
                                {
                                    "comparator": "equal",
                                    "check": false,
                                    "check_value": false,
                                    "expect": false,
                                    "expect_value": false,
                                    "message": "",
                                    "check_result": "pass"
                                },
                                {
                                    "comparator": "greater_than",
                                    "check": "body.results[0].id",
                                    "check_value": 2923,
                                    "expect": 10,
                                    "expect_value": 10,
                                    "message": "",
                                    "check_result": "pass"
                                }
                            ]
                        }
                    },
                    "export_vars": {}
                }
            ]

validate fail

无用字段已经剔除,重点只关注records

{
    "success": false,
    "stat": {
        "testcases": {
            "total": 1,
            "success": 0,
            "fail": 1
        },
        "teststeps": {
            "total": 0,
            "failures": 1,
            "successes": -1
        }
    },
    "details": [
        {
            "name": "case-list",
            "success": false,
            "records": []
        }
    ]
}
@jonzha9527 jonzha9527 added the pending pending for confirmation label Dec 11, 2023
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

1 participant