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.
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)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With