【发布时间】:2020-10-31 20:24:52
【问题描述】:
我正在使用 Locust 对 API 进行负载测试。例如,我正在向 google 发送一个 GET 请求。我的用例是我想通过将函数动态分配给类来使用 setattr 创建 @task 方法。这是我的代码
from locust import TaskSet, HttpUser, between, task
@task
def default_method(self):
self.client.get("/")
class WebsiteTasks(TaskSet):
def on_start(self):
print("start process")
setattr(self, 'index', default_method)
class WebsiteUser(HttpUser):
host = "https://www.google.com"
tasks = [WebsiteTasks]
wait_time = between(1, 10)
作为响应,我在启动新的负载测试浏览器时遇到了该异常:
Exception: No tasks defined. use the @task decorator or set the tasks property of the User
任何帮助将不胜感激
【问题讨论】: