Skip to content

Conversation

@segevfiner
Copy link
Contributor

This works by adding an argparse Action that will raise an exception in
order to skip the rest of the argument parsing. This prevents argparse
from quitting due to missing required arguments, similar to the way that
the builtin argparse --help option is implemented by raising SystemExit.

Fixes: #1999

P.S. I failed to run the tests on Python 3.6 due to pytest-dev/py#103

Thanks for submitting a PR, your contribution is really appreciated!

Here's a quick checklist that should be present in PRs:

  • [V] Add a new news fragment into the changelog folder
    • name it $issue_id.$type for example (588.bug)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of removal, feature, bugfix, vendor, doc or trivial
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."
  • [V] Target: for bugfix, vendor, doc or trivial fixes, target master; for removals or features target features;
  • [V] Make sure to include reasonable tests for your change if necessary

Unless your change is a trivial or a documentation fix (e.g., a typo or reword of a small section) please:

  • [V] Add yourself to AUTHORS;

This works by adding an argparse Action that will raise an exception in
order to skip the rest of the argument parsing. This prevents argparse
from quitting due to missing required arguments, similar to the way that
the builtin argparse --help option is implemented by raising SystemExit.

Fixes: pytest-dev#1999
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f74f14f on segevfiner:fix-required-options-help into ** on pytest-dev:master**.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks a lot for tackling this! 👍



class HelpAction(Action):
def __init__(self,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a short docstring here explaining this action? I guess basically what you wrote on the PR description would be great.



class HelpAction(Action):
"""This is an argparse Action that will raise an exception in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks! 👍

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 9abff7f on segevfiner:fix-required-options-help into ** on pytest-dev:master**.

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.

--help broken when there's a required option set in pytest_addoption()

4 participants