Search code examples
pythonpycharmlocust

Locust/pyCharm: Each end point with N users to achieve X RPS


I am working on Locust/pyCharm project to have separate file for each end point with different no of users to achieve different RPS for each endpoint.

In code snippet below if I remove

if __name__ == '__main__':  ApiUser().run()

and run .py file using command like

locust -f .\locustfiles\test.py --host https://something.another.nothing --users 34 --hatch-rate 10

I see locust working as expected.

Sample code below throws error. What am I missing?

from locust import HttpUser, task, between, TaskSet, User
headerJsonContent = {'Content-Type': 'application/json',  'Accept': 'application/json'}
URL2 = "/Auth/report"
host = "https://something.another.nothing"
NoOfUse = 50
class MyBaseTasks(TaskSet):
    @task
    def getData(self):
        self.client.get(URL2 = "/Auth/report", verify=False)
class ApiUser(HttpUser):
    tasks = [MyBaseTasks]
    wait_time = between(0.100, 1.500)

if __name__ == '__main__':
    ApiUser().run()

*ERROR: *super(HttpUser, self).init(*args, kwargs) TypeError: init() missing 1 required positional argument: 'environment'


Solution

  • Users need an environment parameter. Try something like this:

    from locust.env import Environment
    
    if __name__ == '__main__':
        env = Environment()
        ApiUser(env).run()