Passing values from one task class to another with locust

Viewed 20

I have two user task classes created in locust. I want to be able to pass a random integer generated in one task class to a globally scoped array so that the other task class can access it. This works when I have both task sets in one module. However, is there a way I could have the task classes in separate modules and still be able to do this?

from locust import SequentialTaskSet, task
import random

array_values = []
class User_1_taskSet(SequentialTaskSet):

    @task
    def generate_random_number(self):
        random_int = random.randint(1, 11)
        print("Adding random integer to parent class: ", random_int)
        array_values.append(random_int)

    @task
    def exit_taskSet(self):
        self.interrupt()

class User_2_taskSet(SequentialTaskSet):

    @task
    def second_task(self):
        print("Array Values", array_values)

    @task
    def exit_taskSet(self):
        self.interrupt()
0 Answers
Related