locustio/locust · error · Exception
No tasks defined on {self.user.__class__.__name__}{extra_mes
Error message
No tasks defined on {self.user.__class__.__name__}{extra_message} 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) What it means
User.get_next_task() (for User-based, non-TaskSet users) requires the User class to have tasks. If the User has no tasks and no `task` attribute, it raises, suggesting @task or the tasks attribute, or marking the class abstract.
Source
Thrown at locust/user/task.py:502
"""
Shortcut to the client :py:attr:`client <locust.User.client>` attribute of this TaskSet's :py:class:`User <locust.User>`
"""
return self.user.client
class DefaultTaskSet(TaskSet):
"""
Default root TaskSet that executes tasks in User.tasks.
It executes tasks declared directly on the Locust with the user instance as the task argument.
"""
def get_next_task(self):
if not self.user.tasks:
if getattr(self.user, "task", None):
extra_message = ", but you have set a 'task' attribute on your class - maybe you meant to set 'tasks'?"
else:
extra_message = "."
raise Exception(
f"No tasks defined on {self.user.__class__.__name__}{extra_message} 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)"
)
return random.choice(self.user.tasks)
def execute_task(self, task):
if hasattr(task, "tasks") and issubclass(task, TaskSet):
# task is (nested) TaskSet class
task(self.user).run()
else:
# task is a function
task(self.user)
View on GitHub (pinned to f391a716e1)
Solutions
- Add @task-decorated methods to the User
- Set `tasks = [...]` on the User
- Fix `task` to `tasks` if the singular attribute was set
- Set `abstract = True` on User classes meant only as base classes
Example fix
// before
class MyBaseUser(User):
task = [do_thing]
// after
class MyBaseUser(User):
abstract = True
class MyUser(MyBaseUser):
tasks = [do_thing] Defensive patterns
Strategy: validation
Validate before calling
assert getattr(MyUser, 'tasks', None) or getattr(MyUser, 'abstract', False) or any(callable(v) and getattr(v, 'locust_task_weight', None) for v in vars(MyUser).values()), "User has no tasks"
Prevention
- Set abstract = True on base User classes
- Use plural `tasks` attribute
- Ensure every runnable User has @task methods
When it happens
Trigger: Running a User subclass with no @task methods and no `tasks` list; or setting singular `task` instead of `tasks`.
Common situations: Instantiating base/shared User classes intended only for subclassing; refactoring removed all tasks; typo `task = [...]`.
Related errors
- No tasks defined on {self.__class__.__name__}{extra_message}
- You must define a wait_time method on either the {type(self.
- You must specify the base host. Either in the host attribute
- You must specify the base host. Either in the host attribute
- In order to use a with-block for requests, you must also pas
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/589bdbf2e70499c8.
Report an issue: GitHub.