locustio/locust · error · ImportError
deprecation_message (e.g. The Locust class has been renamed
Error message
deprecation_message (e.g. The Locust class has been renamed to User in version 1.0. Use User instead)
What it means
deprecated_locust_meta_class builds a metaclass that allows only its internal placeholder classes to be created; any subclass of a deprecated Locust/HttpLocust alias raises ImportError with the supplied deprecation message.
Source
Thrown at locust/util/deprecation.py:26
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
class DeprecatedLocustClass(
metaclass=deprecated_locust_meta_class( # type: ignore
"The Locust class has been renamed to User in version 1.0. "
"For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0"
)
):
pass
class DeprecatedHttpLocustClass(
metaclass=deprecated_locust_meta_class( # type: ignore
"The HttpLocust class has been renamed to HttpUser in version 1.0. "
"For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0"View on GitHub (pinned to f391a716e1)
Solutions
- Rename base class from Locust to User
- Rename HttpLocust to HttpUser
- Rename FastHttpLocust to FastHttpUser
- Update imports to the new names from locust
Example fix
// before
from locust import HttpLocust, TaskSet
class MyLocust(HttpLocust):
...
// after
from locust import HttpUser, task, between
class MyUser(HttpUser):
... Defensive patterns
Strategy: validation
Validate before calling
assert not issubclass(MyUser, tuple(b for b in MyUser.__mro__ if getattr(getattr(b, '__class__', None), '__name__', '') == 'MetaClass' or b.__name__ in ('Locust','HttpLocust','FastHttpLocust'))), "Use User/HttpUser instead of deprecated names" Try / catch
try:
class MyLocust(HttpLocust): ...
except ImportError as e:
logging.error("Rename to HttpUser: %s", e) Prevention
- Use User/HttpUser/FastHttpUser in all new code
- Run a 1.0+ migration check on old locustfiles
When it happens
Trigger: Subclassing locust.Locust, HttpLocust, or FastHttpLocust aliases from locust.util.deprecation (pre-1.0 names) after the 1.0 rename.
Common situations: Old locustfiles upgraded to Locust 1.0+ still using `class MyLocust(Locust)` or `HttpLocust`; tutorials predating the rename.
Related errors
- Usage of User.task_set is deprecated since version 1.0. Set
- In order to use a with-block for requests, you must also pas
- Tried to set status on a request that has not yet been made.
- User.run() is a method used internally by Locust, and you mu
- No tag name was supplied
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/866c75b4461e2700.
Report an issue: GitHub.