tag doesn't work fine
Prerequisites
- [X] I am using the latest version of Locust
- [X] I am reporting a bug, not asking a question
Description
With this simple locusfile:
from locust import HttpUser, task, tag
class RevisionApiUser(HttpUser):
@tag('revision')
@task
def get_commit_list(self):
print("revision")
class CBotApiUser(HttpUser):
@tag('cbot')
@task
def get_commits(self):
print("cbot")
Then run locust with a tag specified:
$ locust --tags cbot
[2024-08-14 15:05:43,870] C02GM2X6MD6R/ERROR/locust.user.task: No tasks defined on RevisionApiUser. Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)
Traceback (most recent call last):
File "/Users/chaol/venv/3.9/lib/python3.9/site-packages/locust/user/task.py", line 335, in run
self.schedule_task(self.get_next_task())
File "/Users/chaol/venv/3.9/lib/python3.9/site-packages/locust/user/task.py", line 479, in get_next_task
raise Exception(
Exception: No tasks defined on RevisionApiUser. Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)
From the UI, the test looks run properly, only CBotApiUser is executed. However, the terminal keeps scrolling the error message.
Command line
locust --tags cbot
Locustfile contents
from locust import HttpUser, task, tag
class RevisionApiUser(HttpUser):
@tag('revision')
@task
def get_commit_list(self):
print("revision")
class CBotApiUser(HttpUser):
@tag('cbot')
@task
def get_commits(self):
print("cbot")
Python version
3.9.19
Locust version
locust 2.31.2 from /Users/chaol/venv/3.9/lib/python3.9/site-packages/locust (Python 3.9.19, OpenSSL 3.3.0)
Operating system
MacOS
This is kind of intentional. You are spawning a user with no tasks (after filtering tags) which is usually a mistake, so we should log an error message (although I guess it would be enough to do it once, PRs fixing that would be welcome.)
Instead, you can filter by User class, e.g. locust CBotApiUser, or use --config-users to temporarily give the user class weight = 0.
@cyberw , please assign it to me. I would like to work on this.
I think this is fixed already. I can see the warning message once
See:
The problem (I think) I was referring to is that it gets logged once per user instance. When I think about it though, idk if it is worth fixing. Maybe not.
@skirtan1 , looks like you ran with only one user and that user picked CBotApiUser(alphabetically ordered). If you run with more than one user then you can see the issue.
@cyberw , it would be still good if it gets logged once per user instance instead of throwing exceptions right?
Yes! As long as the implementation can be kept simple.
https://github.com/locustio/locust/pull/2957
@vijay59122 That PR does more than I expected. I dont want to change any behaviour apart from the log spam.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!