AttributeError: type object 'MyApiTask' has no attribute 'task_set' while trying to run locust

AttributeError: type object 'MyApiTask' has no attribute 'task_set' while trying to run locust

我的代码是这样的

class MyApiTask(TaskSet):

    def __init__(self):
        super().__init__(self)

    @task(1)
    def get_response(self):
        response  = self.client.get("/")
        print(response.json())
        assert_that(200).is_equal_to(response.status_code)

class MyApiUser(HttpLocust):
    task_set = MyApiTask
    wait_time = between(1,2)

当我 运行 它时,我得到:

AttributeError:类型对象 'MyApiTask' 在尝试 运行 locust

时没有属性 'task_set'

请帮忙!

您似乎还没有更新到 1.x 语法?

MyApiUser(HttpLocust):

只要看看当前的例子,你应该没问题。

https://docs.locust.io/en/stable/quickstart.html