summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-11-27 11:49:47 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-11-27 11:49:47 -0500
commit08dd0d888e423e5419762464096788e87183bea6 (patch)
tree61292778ac92c4c038cf8e4ef2a759bfd1d21642
parent95fbfd5d96e043c2269b61eb5bd3d92cf060eb26 (diff)
downloadpython-coveragepy-08dd0d888e423e5419762464096788e87183bea6.tar.gz
--fail-under can now be specified in the rcfile. #314
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/cmdline.py36
-rw-r--r--coverage/config.py2
-rw-r--r--tests/test_cmdline.py2
-rw-r--r--tests/test_process.py9
5 files changed, 39 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6cd8e9e..0ab3423 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -15,6 +15,9 @@ Latest
files reported by skipping files with 100% coverage. Thanks, Krystian
Kichewko.
+- You can now specify the ``--fail-under`` option in the ``.coveragerc`` file
+ as the ``[report] fail_under`` options. This closes `issue 314`_.
+
- The ``COVERAGE_OPTIONS`` environment variable is no longer supported. It was
a hack for ``--timid`` before configuration files were available.
@@ -44,6 +47,7 @@ Latest
- Made some PyPy-specific tweaks to improve speed under PyPy. Thanks, Alex
Gaynor.
+.. _issue 314: https://bitbucket.org/ned/coveragepy/issue/314/fail_under-param-not-working-in-coveragerc
.. _issue 328: https://bitbucket.org/ned/coveragepy/issue/328/misbehavior-in-run-source
.. _issue 334: https://bitbucket.org/ned/coveragepy/issue/334/pragma-not-recognized-if-tab-character
.. _issue 342: https://bitbucket.org/ned/coveragepy/issue/342/console-and-html-coverage-reports-differ
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 7ad0ca1..ee8233e 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 d15810e..b14c6d6 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'),
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index e0d1086..3399254 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -4,6 +4,7 @@ import pprint, re, shlex, sys, textwrap
import mock
import coverage
import coverage.cmdline
+from coverage.config import CoverageConfig
from coverage.misc import ExceptionDuringRun
from tests.coveragetest import CoverageTest, OK, ERR
@@ -45,6 +46,7 @@ class BaseCmdLineTest(CoverageTest):
# We'll invoke .coverage as the constructor, and then keep using the
# same object as the resulting coverage object.
mk.coverage.return_value = mk
+ mk.config = CoverageConfig()
return mk
def mock_command_line(self, args):
diff --git a/tests/test_process.py b/tests/test_process.py
index e13ec95..2ed8c4a 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -663,6 +663,15 @@ class FailUnderTest(CoverageTest):
st, _ = self.run_command_status("coverage xml --fail-under=44")
self.assertEqual(st, 2)
+ def test_fail_under_in_config(self):
+ self.make_file(".coveragerc", "[report]\nfail_under = 43\n")
+ st, _ = self.run_command_status("coverage report")
+ self.assertEqual(st, 0)
+
+ self.make_file(".coveragerc", "[report]\nfail_under = 44\n")
+ st, _ = self.run_command_status("coverage report")
+ self.assertEqual(st, 2)
+
def possible_pth_dirs():
"""Produce a sequence of directories for trying to write .pth files."""