Skip to content

Commit

Permalink
Add --user-config parser argument
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldwin44 committed Jan 18, 2024
1 parent 0561adb commit 4285fd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ def setup_parser_arguments(parser):
dest="list_commands",
help="Show list of possible User classes and exit",
)
parser.add_argument(
"--user-config",
type=str,
help="User configuration in JSON format",
env_var="LOCUST_USER_CONFIG",
)

web_ui_group = parser.add_argument_group("Web UI options")
web_ui_group.add_argument(
Expand Down
14 changes: 14 additions & 0 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import errno
import logging
import os
import json
import signal
import sys
import time
Expand Down Expand Up @@ -358,6 +359,19 @@ def kill_workers(children):
available_user_tasks=available_user_tasks,
)

if options.user_config:
try:
user_config = json.loads(options.user_config)

if "user_class_name" not in user_config:
logger.error("The user config must specify a user_class_name")
sys.exit(-1)

environment.update_user_class(user_config)
except Exception as e:
logger.error(f"The --user-config arugment must be in valid JSON format: {e}")
sys.exit(-1)

if (
shape_class
and not shape_class.use_common_options
Expand Down

0 comments on commit 4285fd2

Please sign in to comment.