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

Improve argument validation a bit. #480

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,23 @@ def validate_report(arg):

def validate_fail_under(num_str):
try:
return int(num_str)
value = int(num_str)
except ValueError:
return float(num_str)
try:
value = float(num_str)
except ValueError:
raise argparse.ArgumentTypeError('An integer or float value is required.')
if value > 100:
raise argparse.ArgumentTypeError('Your desire for over-achievement is admirable but misplaced. '
'The maximum value is 100. Perhaps write more integration tests?')
return value


def validate_context(arg):
if coverage.version_info <= (5, 0):
raise argparse.ArgumentTypeError('Contexts are only supported with coverage.py >= 5.x')
if arg != "test":
raise argparse.ArgumentTypeError('--cov-context=test is the only supported value')
raise argparse.ArgumentTypeError('The only supported value is "test".')
return arg


Expand Down