diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-27 11:49:47 -0500 |
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-27 11:49:47 -0500 |
| commit | cbfb93fb4a4b432d7a7a3648433412e614fc1d80 (patch) | |
| tree | ed87ddf4c747fefc695abbf0b4629262808d71a8 /coverage | |
| parent | 483a3700cca817c37192979499b155a9c1200ad6 (diff) | |
| download | python-coveragepy-git-cbfb93fb4a4b432d7a7a3648433412e614fc1d80.tar.gz | |
--fail-under can now be specified in the rcfile. #314
Diffstat (limited to 'coverage')
| -rw-r--r-- | coverage/cmdline.py | 36 | ||||
| -rw-r--r-- | coverage/config.py | 2 |
2 files changed, 24 insertions, 14 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 7ad0ca1e..ee8233ef 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -430,6 +430,7 @@ class CoverageScript(object): include = include, ) + total = None if options.action == "report": total = self.coverage.report( show_missing=options.show_missing, @@ -445,21 +446,28 @@ class CoverageScript(object): outfile = options.outfile total = self.coverage.xml_report(outfile=outfile, **report_args) - if options.fail_under is not None: - # Total needs to be rounded, but be careful of 0 and 100. - if 0 < total < 1: - total = 1 - elif 99 < total < 100: - total = 99 - else: - total = round(total) + if total is not None: + # Apply the command line fail-under options, and then use the config + # value, so we can get fail_under from the config file. + if options.fail_under is not None: + self.coverage.config["report:fail_under"] = options.fail_under - if total >= options.fail_under: - return OK - else: - return FAIL_UNDER - else: - return OK + if self.coverage.config["report:fail_under"]: + + # Total needs to be rounded, but be careful of 0 and 100. + if 0 < total < 1: + total = 1 + elif 99 < total < 100: + total = 99 + else: + total = round(total) + + if total >= self.coverage.config["report:fail_under"]: + return OK + else: + return FAIL_UNDER + + return OK def help(self, error=None, topic=None, parser=None): """Display an error message, or the named topic.""" diff --git a/coverage/config.py b/coverage/config.py index d15810e4..b14c6d6a 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -153,6 +153,7 @@ class CoverageConfig(object): # Defaults for [report] self.exclude_list = DEFAULT_EXCLUDE[:] + self.fail_under = 0 self.ignore_errors = False self.include = None self.omit = None @@ -252,6 +253,7 @@ class CoverageConfig(object): # [report] ('exclude_list', 'report:exclude_lines', 'linelist'), + ('fail_under', 'report:fail_under', 'int'), ('ignore_errors', 'report:ignore_errors', 'boolean'), ('include', 'report:include', 'list'), ('omit', 'report:omit', 'list'), |
