Locust: Does locust support ‘CSV Data Set Config‘ feature like jmeter

Created on 5 Jun 2013  Â·  3Comments  Â·  Source: locustio/locust

I am newcomer from Jmeter background, I want to get some help.

just like the example in [Quick start] section in doc of locust,
how could I share the thousands of pairs of userid and password between all threads like jmeter do?
Does locust support ‘CSV Data Set Config‘ feature like jmeter?

Most helpful comment

Hi!

Locust tests are essentially just python code so you just need to write code that reads your CSV file. For example, you could put this code at the module level in your load testing scripts. Here's a small pseudo code example:

# locustfile.py

import random
from locust import Locust, TaskSet, task

# load user credentials from CSV
user_credentials = read_user_credentials_from_csv()

class MyTasks(TaskSet):
    def on_start(self):
        credentials = random.choice(user_credentials)
        self.client.post("/login/", {"username":credentials[0], "password":credentials[1]})

    @task
    def some_task(self):
        ...

class MyLocust(Locust):
    task_set = MyTasks

All 3 comments

Hi!

Locust tests are essentially just python code so you just need to write code that reads your CSV file. For example, you could put this code at the module level in your load testing scripts. Here's a small pseudo code example:

# locustfile.py

import random
from locust import Locust, TaskSet, task

# load user credentials from CSV
user_credentials = read_user_credentials_from_csv()

class MyTasks(TaskSet):
    def on_start(self):
        credentials = random.choice(user_credentials)
        self.client.post("/login/", {"username":credentials[0], "password":credentials[1]})

    @task
    def some_task(self):
        ...

class MyLocust(Locust):
    task_set = MyTasks

thank you very much, I will try it

Just in case anyone stumbles upon this, there is a longer blog post on this topic at https://www.blazemeter.com/blog/how-to-run-locust-with-different-users/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

gboorse picture gboorse  Â·  3Comments

bretrouse picture bretrouse  Â·  4Comments

ashleigh-robinson picture ashleigh-robinson  Â·  3Comments

ShaolongHu picture ShaolongHu  Â·  3Comments