httprunner4.0,前端传过来的json,执行不了。报错

问题

httprunner4.0,前端传过来的json,执行不了。报错
代码

from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
#httprunner 4.3  python 3.10
testcase = {
    "config": {
        "name": "test case name",
        "base_url": "http://baidu.com"
    },
    "teststeps": [
        {
            "name": "get request",
            "request": {
                "method": "GET",
                "url": "/get"
            },
            "validate": [
                {
                    "equals": ["status_code", 200]
                }
            ]
        }
    ]
}


runner = HttpRunner()

runner.test_start(testcase.get('teststeps'))

报错信息

D:\rj\Python\python3.10\python.exe D:/rj/python_code/seer_utils/Tool/httprunner/11.py
Traceback (most recent call last):
File “D:\rj\python_code\seer_utils\Tool\httprunner\11.py”, line 27, in
runner.test_start(testcase.get(‘teststeps’))
File “D:\rj\Python\python3.10\lib\site-packages\httprunner\runner.py”, line 215, in test_start

self.__init()

File “D:\rj\Python\python3.10\lib\site-packages\httprunner\runner.py”, line 57, in __init
self.__config = self.config.struct()
AttributeError: ‘HttpRunner’ object has no attribute ‘config’

环境

httprunner 4.3 python 3.10

你这不是httprunner的case格式

你可以把这个json放到一个文件

demo.json

{
    "config": {
        "name": "test case name",
        "base_url": "https://baidu.com"
    },
    "teststeps": [
        {
            "name": "get request",
            "request": {
                "method": "GET",
                "url": "/get"
            },
            "validate": [
                {
                    "equals": ["status_code", 200]
                }
            ]
        }
    ]
}

然后使用hrun demo.json

或者你要么就按照官方给的写法 去写py

from httprunner import HttpRunner, Config, Step, RunRequest


class TestCaseDemo1(HttpRunner):

    config = Config("test case name").base_url("https://baidu.com")

    teststeps = [
        Step(
            RunRequest("get request")
            .get("/get")
            .validate()
            .assert_equal("status_code", 200)
        ),
    ]


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