【发布时间】:2020-06-23 10:29:48
【问题描述】:
尝试运行我的 Locust 文件,同时在尝试命令 locust -f locustfile.py --host=http://localhost:8080 时遇到以下错误
文件 "/home/sonali/.local/lib/python3.6/site-packages/locust/user/task.py", 第 280 行,运行中 self.schedule_task(self.get_next_task()) 文件“/home/sonali/.local/lib/python3.6/site-packages/locust/user/task.py”, 第 408 行,在 get_next_task 中 返回 random.choice(self.user.tasks) 文件“/usr/lib/python3.6/random.py”,第 260 行,选择 raise IndexError('Cannot choose from an empty sequence') from None 不能从空序列中选择
我的locust文件如下:
from locust import HttpUser, task, between ,TaskSet
class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before
any task is scheduled
"""
self.login()
def login(self):
self.client.post("/login",
{"username":"ellen_key",
"password":"education"})
@task(2)
def index(self):
self.client.get("/")
@task(1)
def profile(self):
self.client.get("/profile")
class WebsiteUser(HttpUser):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
【问题讨论】: