ahoyt41
ahoyt41

Reputation: 37

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.

Upvotes: 3

Views: 5036

Answers (1)

Cyberwiz
Cyberwiz

Reputation: 11426

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)

Upvotes: 11

Related Questions