Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add custom locust command line arguments

I'm wondering if there is a way to pass custom command-line/configuration arguments to locust. I am currently passing in my user credentials into my test as environment variables but I would like to pass them in through the command line with something that would look like this:

locust -f <locustfile> --host <host> --username <username> --password  <password>

Ideally I would like to avoid creating my own custom extension of locust but I'm gonna guess that I will have to in order to this. I'd be happy to hear any suggestions.

like image 828
ahoyt41 Avatar asked Nov 01 '25 10:11

ahoyt41


1 Answers

Yes! There’s an example on github: https://github.com/locustio/locust/blob/master/examples/add_command_line_argument.py

@events.init_command_line_parser.add_listener
def init_parser(parser):
    parser.add_argument(
        '--my-argument',
        help="It's working"
    )

class WebsiteUser(HttpUser):
    @task
    def my_task(self):
        print(self.environment.parsed_options.my_argument)
like image 190
Cyberwiz Avatar answered Nov 04 '25 01:11

Cyberwiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!