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.0

View on GitHub (pinned to f391a716e1)

Solutions

  1. Add @task-decorated methods to the TaskSet
  2. Set the `tasks` attribute (list of callables or TaskSet classes)
  3. If `task` was set, rename it to `tasks` (plural)
  4. 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

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


AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29). Data as JSON: /api/errors/3c0215256a2af490. Report an issue: GitHub.