locustio/locust · error · Exception
No tasks defined on {self.__class__.__name__}{extra_message}
Error message
No tasks defined on {self.__class__.__name__}{extra_message} use the @task decorator or set the 'tasks' attribute of the TaskSet What it means
TaskSet.get_next_task() picks a random task from self.tasks; if the TaskSet has no tasks and no `task` attribute, it cannot proceed and raises. This is raised at runtime when the TaskSet starts running.
Source
Thrown at locust/user/task.py:428
def schedule_task(self, task_callable, first=False):
"""
Add a task to the User's task execution queue.
:param task_callable: User task to schedule.
:param first: Optional keyword argument. If True, the task will be put first in the queue.
"""
if first:
self._task_queue.appendleft(task_callable)
else:
self._task_queue.append(task_callable)
def get_next_task(self):
if not self.tasks:
if getattr(self, "task", None):
extra_message = ", but you have set a 'task' attribute - maybe you meant to set 'tasks'?"
else:
extra_message = "."
raise Exception(
f"No tasks defined on {self.__class__.__name__}{extra_message} use the @task decorator or set the 'tasks' attribute of the TaskSet"
)
return random.choice(self.tasks)
def wait_time(self):
"""
Method that returns the time (in seconds) between the execution of tasks.
Example::
from locust import TaskSet, between
class Tasks(TaskSet):
wait_time = between(3, 25)
"""
if self.user.wait_time:
return self.user.wait_time()
elif self.min_wait is not None and self.max_wait is not None:
return random.randint(self.min_wait, self.max_wait) / 1000.0View on GitHub (pinned to f391a716e1)
Solutions
- Add @task-decorated methods to the TaskSet
- Set the `tasks` attribute (list of callables or TaskSet classes)
- If `task` was set, rename it to `tasks` (plural)
- Mark base classes as abstract by not instantiating them directly
Example fix
// before
class MyTaskSet(TaskSet):
task = [other_task] # wrong
// after
class MyTaskSet(TaskSet):
tasks = [other_task] Defensive patterns
Strategy: validation
Validate before calling
assert getattr(MyTaskSet, 'tasks', None) or any(callable(v) and getattr(v, 'locust_task_weight', None) for v in vars(MyTaskSet).values()), "TaskSet has no tasks"
Prevention
- Give every concrete TaskSet at least one @task method
- Use plural `tasks` attribute name
- Mark base-only classes abstract in naming/docs
When it happens
Trigger: Defining a TaskSet subclass with no @task methods and no `tasks` attribute; or setting the singular `task` attribute instead of `tasks` (extra hint message).
Common situations: Empty TaskSet skeletons left after refactoring; misspelling `tasks`; forgetting to mark abstract base classes.
Related errors
- You must define a wait_time method on either the {type(self.
- No tasks defined on {self.user.__class__.__name__}{extra_mes
- 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/3c0215256a2af490.
Report an issue: GitHub.