Skip to content

Commit

Permalink
Merge pull request #480 from pytest-dev/funny-arg-validation
Browse files Browse the repository at this point in the history
Improve argument validation a bit.
  • Loading branch information
ionelmc authored Aug 26, 2021
2 parents f62c9eb + d976cde commit f748779
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit f748779

Please sign in to comment.