Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locust decorators #1036

Closed
rahul-jain101 opened this issue Jun 25, 2019 · 1 comment
Closed

Locust decorators #1036

rahul-jain101 opened this issue Jun 25, 2019 · 1 comment

Comments

@rahul-jain101
Copy link

Is there a way to me for class-decorate the task class? Just wondering because when I do, the class decorator gets ignored, but when I do
@task
@decorator
underneath each method it seems to work, but when I do:

@class_decorator
class CustomTaskSet(TaskSet):
@task
def task_1(self):
stuff()

@heyman
Copy link
Member

heyman commented Oct 21, 2019

Hi! From your description, I'm not able to decipher what the issue is. Could you provide a minimal reproducible code example? I've tested with the following code which seems to work fine:

from locust import HttpLocust, TaskSet, task
from locust.contrib.fasthttp import FastHttpLocust


def class_decorator(original_class):
    orig_init = original_class.__init__
    def __init__(self, *args, **kws):
        print("class_decorator")
        orig_init(self, *args, **kws)

    original_class.__init__ = __init__
    return original_class

@class_decorator
class UserTasks(TaskSet):
    @task
    def index(self):
        self.client.get("/")
    
    @task
    def stats(self):
        self.client.get("/stats/requests")


class WebsiteUser(FastHttpLocust):
    """
    Locust user class that does requests to the locust web server running on localhost
    """
    host = "http://127.0.0.1:8089"
    min_wait = 2000
    max_wait = 5000
    task_set = UserTasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants