【问题标题】:Is it possible to add custom locust command line arguments是否可以添加自定义蝗虫命令行参数
【发布时间】:2020-07-27 17:54:16
【问题描述】:

我想知道是否有办法将自定义命令行/配置参数传递给 locust。我目前正在将我的用户凭据作为环境变量传递到我的测试中,但我想通过命令行将它们传递给如下所示的内容:

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

理想情况下,我想避免创建自己的自定义蝗虫扩展,但我猜我必须这样做。我很乐意听到任何建议。

【问题讨论】:

    标签: python-3.x locust


    【解决方案1】:

    是的! 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)
    

    【讨论】:

    • 这是否也允许我在我的配置文件中添加自定义参数,还是需要添加另一个监听器?
    • 是的,它也应该与配置文件和环境变量一起使用,但如果不能,请告诉我:)
    • 它工作得很好,再次感谢您对 Cyber​​wiz 的所有帮助
    • 如何访问User类中传入的值?
    • 链接示例中都包含,但我现在将其添加到我的答案中
    猜你喜欢
    • 2011-04-06
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    • 2011-06-14
    • 2021-09-14
    相关资源
    最近更新 更多