It is my first time to use locust for load testing. My config file is:
locustfile = locustfile.py
headless = true
master = false
# expect-workers = 5
users = 200
spawn-rate = 10
run-time = 10m
tags = [Critical, Normal]
My locustfile.py is the following:
from locust import HttpUser, task, between
class StaticWebSite(HttpUser):
wait_time = between(1, 5)
host = "https://example.com"
@task
def index(self):
self.client.get("/")
@task
def boat(self):
self.client("/other_page")
When I execute locust, I get the following error:
File "/home/roland/.cache/pypoetry/virtualenvs/bnw-new-5YYRTg7r-py3.11/lib/python3.11/site-packages/locust/user/task.py", line 479, in get_next_task
raise Exception(
Exception: No tasks defined on StaticWebSite. Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)
Obviously the code has the @task decorator, so I do not have any idea why it is not recognized.
In your config file, you have tags=[Critical, Normal]
. That means you have Locust set to look for tasks that are tagged with either of those tags in order to run. It will skip any tasks that aren't tagged with either of those. You'll need to either remove that line from your config file or tag your tasks.
https://docs.locust.io/en/latest/api.html#locust.env.Environment.tags https://docs.locust.io/en/latest/writing-a-locustfile.html#tag-decorator