locustio/locust · critical · StopTest
You must specify the base host. Either in the host attribute
Error message
You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option.
What it means
HttpUser.__init__ requires a base host to build its HttpSession. If self.host is None (not set on the class nor via --host), it raises StopTest during user instantiation.
Source
Thrown at locust/user/users.py:274
The behaviour of this user is defined by its tasks. Tasks can be declared either directly on the
class by using the :py:func:`@task decorator <locust.task>` on methods, or by setting
the :py:attr:`tasks attribute <locust.User.tasks>`.
This class creates a *client* attribute on instantiation which is an HTTP client with support
for keeping a user session between requests.
"""
abstract: bool = True
"""If abstract is True, the class is meant to be subclassed, and users will not choose this locust during a test"""
pool_manager: PoolManager | None = None
"""Connection pool manager to use. If not given, a new manager is created per single user."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.host is None:
raise StopTest(
"You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option."
)
self.client = HttpSession(
base_url=self.host,
request_event=self.environment.events.request,
user=self,
pool_manager=self.pool_manager,
)
"""
Instance of HttpSession that is created upon instantiation of Locust.
The client supports cookies, and therefore keeps the session between HTTP requests.
"""
self.client.trust_env = False
class PytestUser(User):
abstract = TrueView on GitHub (pinned to f391a716e1)
Solutions
- Set `host = "https://example.com"` on the User class
- Pass --host=https://example.com on the command line
- Provide host via environment variable/config when launching
Example fix
// before
class MyUser(HttpUser):
tasks = [my_task]
// after
class MyUser(HttpUser):
host = "https://example.com"
tasks = [my_task] Defensive patterns
Strategy: validation
Validate before calling
assert MyUser.host, "Set host attribute on User or pass --host"
Try / catch
try:
runner = Environment(user_classes=[MyUser]).create_local_runner()
except StopTest:
... Prevention
- Always set `host` on HttpUser classes
- Include --host in run scripts/CI commands
When it happens
Trigger: Instantiating an HttpUser subclass with no `host` class attribute and without passing --host on the command line (or host in environment config).
Common situations: Running `locust -f locustfile.py` without --host; forgetting host when running headless; hosts defined only in subclasses that aren't picked.
Related errors
- No tasks defined on {self.__class__.__name__}{extra_message}
- You must define a wait_time method on either the {type(self.
- No tasks defined on {self.user.__class__.__name__}{extra_mes
- 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.
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/1b625ee2407a6ede.
Report an issue: GitHub.