Add @only decorator to TaskSets
See original GitHub issueIs your feature request related to a problem? Please describe.
Whenever I want to add a new task to one of the TaskSets, I have to manually set all @task decorators’ weights to 0 (or comment them) in order to be able to debug the new task; otherwise I have to wait until the locust randomly pick the new task.
Describe the solution you’d like
Create a @only decorator. This decorator would be attachable to methods in TaskSet classes and would cause that method to be always be called instead of the other tasks. This should be effectively equivalent to setting all existing @task decorators’ weights of that class to 0.
e.g.
@task(4)
def my_task(self):
...
@task(6)
def my_other_task(self):
...
@only
@task(3)
def task_being_tested(self):
...
should behave the same as
@task(0)
def my_task(self):
...
@task(0)
def my_other_task(self):
...
@task(1)
def task_being_tested(self):
...
This is inspired by test frameworks that let you run a single test in a suite so that you can debug it.
Describe alternatives you’ve considered
Manually setting all other @task weights to 0, or commenting them.
Additional context
N/A
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
TaskSet class — Locust 2.14.0 documentation
TaskSets are an advanced feature and only rarely useful. ... A TaskSet can also be inlined directly under a User/TaskSet class using the...
Read more >Locust - How do I define multiple task sets for the same user?
I think I got it. To solve the problem I had to add a method at the end of each taskset to stop...
Read more >Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create ... This means that only a reference to...
Read more >fabric-taskset - PyPI
TaskSet is a class that can expose its methods as Fabric tasks. ... taskset.task_method is a decorator declaring the wrapped method to be...
Read more >Locust - Read the Docs
possible to define the tasks of a TaskSet by setting the tasks attribute (using the @task decorator will actually just.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is great idea, infact I would suggest to go one step ahead and instead of adding a decorator, to mark to run only that specific task, use markers concept of pytest framework (doc link).
so for the tasks defined as below:
and say executed like:
then only
my_task
should be executed.Let me know what you all think about this suggestion.
Thought I’d let y’all know that I’ve started implementing this in my fork, will make a PR sometime soon assuming the maintainers are interested in this feature