locustio / locust

Write scalable load tests in plain Python 🚗💨
https://locust.cloud
MIT License
24.88k stars 2.98k forks source link

Custom arguments' help is not shown when calling `locust --help` #2917

Open fstamour opened 4 weeks ago

fstamour commented 4 weeks ago

Prerequisites

Description

(I'm not certain you would consider this a bug or a feature request.)

How to reproduce

  1. Create a locust.conf file in the current directory
  2. Add custom arguments
  3. Run locust --help (or even locust -f locustfile.py)

Expected result

Actual result

Possible fix

Replace the built-in help action by something that loads the locustfile before printing the help.

Command line

locust --help

Locustfile contents

import argparse

from locust import events

print("top-level")

@events.init_command_line_parser.add_listener
def init_command_line_parser(parser: argparse.ArgumentParser):
    """
    Initialize the command line parser with custom arguments.
    """
    print("init_command_line_parser")

    parser.add_argument(
        "--my-little-argument",
        type=str,
        help="Choose a custom load shape",
        choices=["a", "b", "c"],
    )

Python version

Test with both Python 3.10.12 and 3.12.6

Locust version

2.31.6

Operating system

Ubuntu 22.04.4 LTS and 24.04 LTS

cyberw commented 1 week ago

Yea this is a real bug. I think your suggested fix sounds reasonable and would love for you to PR it!

shubhamsugara22 commented 1 week ago

@fstamour is anyone working this ? , would like to have a crack at it

shauryapanchal commented 3 days ago

I would like to work on this if there's any chance..? @cyberw

cyberw commented 3 days ago

Go for it. I meant to assign it to you.