Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
fstamour opened this issue Sep 27, 2024 · 2 comments
Open
2 tasks done

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

fstamour opened this issue Sep 27, 2024 · 2 comments
Assignees
Labels
bug hacktoberfest See https://hacktoberfest.digitalocean.com for more info

Comments

@fstamour
Copy link

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

  • I expect locust to load the locustfile.py and run the init_command_line_parser hook
  • I expect to see my custom arguments' help to be shown in locust --help 's output

Actual result

  • The locustfile.py is not loaded at all when running locust --help.
  • The custom arguments' help are not shown in locust --help 's output.

Possible fix

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

  • Add an explicit --help argument (parser.add_argument('-h', '--help', action="store_true" ...)
  • Check if args.help == True
  • Call parser.print_help() and parser.exit() (just like the default _HelpAction does)

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

@fstamour fstamour added the bug label Sep 27, 2024
@cyberw
Copy link
Collaborator

cyberw commented Oct 13, 2024

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

@cyberw cyberw added the hacktoberfest See https://hacktoberfest.digitalocean.com for more info label Oct 13, 2024
@shubhamsugara22
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug hacktoberfest See https://hacktoberfest.digitalocean.com for more info
Projects
None yet
Development

No branches or pull requests

3 participants