【发布时间】:2020-06-02 21:10:25
【问题描述】:
我正在尝试运行 Locust 文件并反复遇到以下错误:
Traceback (most recent call last):
File "/Applications/anaconda/lib/python3.6/site-packages/locust/user/task.py", line 280, in run
self.schedule_task(self.get_next_task())
File "/Applications/anaconda/lib/python3.6/site-packages/locust/user/task.py", line 408, in get_next_task
return random.choice(self.user.tasks)
File "/Applications/anaconda/lib/python3.6/random.py", line 260, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
我的 locust 文件如下所示:
import base64
from locust import HttpUser, TaskSet, task
from random import randint, choice
class WebTasks(TaskSet):
@task
def load(self):
base64string = base64.encodebytes(('%s:%s' % ('user', 'password')).encode()).decode().replace('\n', '')
catalogue = self.client.get("/catalogue").json()
category_item = choice(catalogue)
item_id = category_item["id"]
self.client.get("/")
self.client.get("/login", headers={"Authorization":"Basic %s" % base64string})
self.client.get("/category.html")
self.client.get("/detail.html?id={}".format(item_id))
self.client.delete("/cart")
self.client.post("/cart", json={"id": item_id, "quantity": 1})
self.client.get("/basket.html")
self.client.post("/orders")
class Web(HttpUser):
task_set = WebTasks
min_wait = 0
max_wait = 0
我相信这个问题通常是由于没有定义任何任务引起的,但我确实在这里定义了一个任务,所以我不确定我为什么会收到这个错误。我在 Mac OS 上运行 Python 3.6.8 和 Locust 1.0.2。
【问题讨论】:
-
顺便说一句,您没有使用专用的 Conda 环境吗?