Custom arguments
您可以使用init_command_line_parser事件向Locust添加自己的命令行参数。自定义参数也可以在web UI中显示和编辑。
from locust import HttpUser, task, events
@events.init_command_line_parser.add_listener
def _(parser):
parser.add_argument("--my-argument", type=str, env_var="LOCUST_MY_ARGUMENT", default="", help="It's working")
# Set `include_in_web_ui` to False if you want to hide from the web UI
parser.add_argument("--my-ui-invisible-argument", include_in_web_ui=False, default="I am invisible")
@events.test_start.add_listener
def _(environment, **kw):
print(f"Custom argument supplied: {environment.parsed_options.my_argument}")
class WebsiteUser(HttpUser):
@task
def my_task(self):
print(f"my_argument={self.environment.parsed_options.my_argument}")
print(f"my_ui_invisible_argument={self.environment.parsed_options.my_ui_invisible_argument}")
当运行Locust分布式时,自定义参数会在运行开始时自动转发给worker(但在此之前不会,因此在测试真正开始之前不能依赖转发的参数)。
本文介绍如何在Locust中添加自定义命令行参数,这些参数也将在分布式压力测试时自动转发给worker。通过init_command_line_parser事件,用户可以扩展Locust的功能并自定义测试配置。

1076

被折叠的 条评论
为什么被折叠?



