2

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.

Martin Del Vecchio
  • 3,558
  • 2
  • 27
  • 36
  • 1
    Possible duplicate of [how to pass custom parameters to a locust test class?](https://stackoverflow.com/questions/28951458/how-to-pass-custom-parameters-to-a-locust-test-class) – Yushin Washio May 14 '19 at 13:37

2 Answers2

0

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 "))
Ruli
  • 2,592
  • 12
  • 30
  • 40
-1

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.

jheld
  • 148
  • 2
  • 8