How do I add a custom command-line argument to Python Locust?

1.9k views Asked by At

How do I add a custom command-line argument to Python Locust 0.7.2, then retrieve its value?

I want to specify a number:

locust --my-argument 6

Then in my script, I want to retrieve the value, with something like:

my_argument = ??.options.my_argument

I have found this in locust/main.py

def main():
    parser, options, arguments = parse_options()

But it appears that the parse_options() function doesn't look externally for any additional arguments.

Is this possible?

Thanks.

2

There are 2 answers

0
jheld On

You could edit the file (or fork the project) to enable additional optional arguments. It is open source and has a permissive license, after all.

0
Ertuğrul KOMUT On

You can use Environment.

c:\locust>set env_test = ekomut
c:\locust>locust ...

import os
....
 def on_start(self):
        print("Variable:"+os.environ.get("env_test "))