locustio/locust · warning · DeprecationWarning

Usage of User.task_set is deprecated since version 1.0. Set

Error message

Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead (tasks = [{task_set.__name__}])

What it means

check_for_deprecated_task_set_attribute emits a DeprecationWarning when a User class dict contains a `task_set` attribute set to a TaskSet subclass — the pre-1.0 API. It still warns (does not raise) telling users to use `tasks` instead.

Source

Thrown at locust/util/deprecation.py:13

import warnings

# Show deprecation warnings
warnings.filterwarnings("always", category=DeprecationWarning, module="locust")


def check_for_deprecated_task_set_attribute(class_dict):
    from locust.user.task import TaskSet

    if "task_set" in class_dict:
        task_set = class_dict["task_set"]
        if issubclass(task_set, TaskSet) and not hasattr(task_set, "locust_task_weight"):
            warnings.warn(
                "Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead "
                f"(tasks = [{task_set.__name__}])",
                DeprecationWarning,
            )


def deprecated_locust_meta_class(deprecation_message):
    class MetaClass(type):
        def __new__(mcs, classname, bases, class_dict):
            if classname in ["DeprecatedLocustClass", "DeprecatedHttpLocustClass", "DeprecatedFastHttpLocustClass"]:
                return super().__new__(mcs, classname, bases, class_dict)
            else:
                raise ImportError(deprecation_message)

    return MetaClass


# PEP 484 specifies "Generic metaclasses are not supported", see https://github.com/python/mypy/issues/3602, ignore typing errors

View on GitHub (pinned to f391a716e1)

Solutions

  1. Replace `task_set = MyTaskSet` with `tasks = [MyTaskSet]`
  2. Add @task(weight) weighting if different task sets need different frequencies
  3. Run with -W error::DeprecationWarning in CI to catch old patterns

Example fix

// before
class MyUser(User):
    task_set = MyTaskSet
// after
class MyUser(User):
    tasks = [MyTaskSet]
Defensive patterns

Strategy: validation

Validate before calling

assert 'task_set' not in vars(MyUser), "Use tasks = [MyTaskSet] instead of task_set"

Try / catch

import warnings
with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always")
    # import locustfile
    assert not any(issubclass(x.category, DeprecationWarning) for x in w)

Prevention

When it happens

Trigger: Defining a User class with `task_set = SomeTaskSet` (singular) rather than `tasks = [SomeTaskSet]`, where the TaskSet has no locust_task_weight.

Common situations: Migrating locustfiles from Locust 0.x to 1.0+; old documentation examples using task_set.

Related errors


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