question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add @only decorator to TaskSets

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
abhijitmamardecommented, Mar 11, 2020

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:

@mark("admin")
@task(3)
def my_task(self):
    ...
@task(2)
def my_other_task(self):
    ...
@task(1)
def task_being_tested(self):
    ...

and say executed like:

$ locust -f locustfile.py -m admin

then only my_task should be executed.

Let me know what you all think about this suggestion.

2reactions
Trouvcommented, Apr 27, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found