Skip to content

Conversation

@jFompe
Copy link

@jFompe jFompe commented Nov 8, 2025

Addresses #3260

This adds web UI support for a dropdown list in custom arguments with multiple selection:
image

Code:

parser.add_argument("--endpoints", choices=["status", "test", "users"], is_multiple=True, default=["status"], help="Endpoints")

Testing

I ran locally with run-local-web.sh and run-local-headless.sh on Ubuntu 24.04 in a virtual env with Python 3.12.3.

Also I added 3 tests to test_web.py and ran the file with pytest locust/test/test_web.py. All the tests passed.

Also used this code to check that the parsed value was always the expected one:

@events.test_start.add_listener
def on_test_start(environment, **kwargs):
    endpoints = environment.parsed_options.endpoints
    print(f"Argument endpoints. Type: {type(endpoints)}. Value: {endpoints}")

Tests with run-local-web.sh

Web UI mode, select multiple:
Argument endpoints. Type: <class 'list'>. Value: ['status', 'test', 'users']

Web UI mode, select one:
Argument endpoints. Type: <class 'list'>. Value: ['users']

Tests with run-local-headless.sh

Headless mode, select one.

"${VIRTUAL_ENV}/bin/python" -m locust \
  --locustfile "${script_dir}/locustfile.py" \
  --endpoints users \
  --headless \
  --host "https://example.com" \
  --loglevel "INFO"

Argument endpoints. Type: <class 'list'>. Value: ['users']

Headless mode, select multiple.

"${VIRTUAL_ENV}/bin/python" -m locust \
  --locustfile "${script_dir}/locustfile.py" \
  --endpoints users status \
  --headless \
  --host "https://example.com" \
  --loglevel "INFO"

Argument endpoints. Type: <class 'list'>. Value: ['users', 'status']

NOTE: for using this in headless mode it is necessary to add nargs='+' in add_argument.
For example:

parser.add_argument("--endpoints", nargs='+', choices=["status", "test", "users"], is_multiple=True, default=["status"], help="Endpoints")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant