summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt5
-rw-r--r--coverage/control.py21
-rw-r--r--tests/test_config.py15
3 files changed, 37 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 3650a5a..7617fa7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,10 @@ Latest
- Added 3.5.0a1 to the list of supported versions.
+- If the `config_file` argument to the Coverage constructor is specified as
+ ".coveragerc", it is treated as if it were True. This means setup.cfg is
+ also examined, and a missing file is not considered an error (`issue 357`_).
+
- Wildly experimental: support for measuring processes started by the
multiprocessing module. To use, set ``--concurrency=multiprocessing``,
either on the command line or in the .coveragerc file (`issue 117`_). Thanks,
@@ -26,6 +30,7 @@ Latest
.. _issue 117: https://bitbucket.org/ned/coveragepy/issue/117/enable-coverage-measurement-of-code-run-by
.. _issue 340: https://bitbucket.org/ned/coveragepy/issue/340/keyerror-subpy
.. _issue 353: https://bitbucket.org/ned/coveragepy/issue/353/40a3-introduces-an-unexpected-third-case
+.. _issue 357: https://bitbucket.org/ned/coveragepy/issue/357/behavior-changed-when-coveragerc-is
Version 4.0a4 --- 25 January 2015
diff --git a/coverage/control.py b/coverage/control.py
index 7532d29..65830ee 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -78,10 +78,19 @@ class Coverage(object):
If `branch` is true, then branch coverage will be measured in addition
to the usual statement coverage.
- `config_file` determines what config file to read. If it is a string,
- it is the name of the config file to read. If it is True, then a
- standard file is read (".coveragerc"). If it is False, then no file is
- read.
+ `config_file` determines what configuration file to read:
+
+ * If it is ".coveragerc", it is interpreted as if it were True,
+ for backward compatibility.
+
+ * If it is a string, it is the name of the file to read. If the
+ file can't be read, it is an error.
+
+ * If it is True, then a few standard files names are tried
+ (".coveragerc", "setup.cfg"). It is not an error for these files
+ to not be found.
+
+ * If it is False, then no configuration file is read.
`source` is a list of file paths or package names. Only code located
in the trees indicated by the file paths or package names will be
@@ -107,6 +116,10 @@ class Coverage(object):
# 2: from the rcfile, .coveragerc or setup.cfg file:
if config_file:
did_read_rc = False
+ # Some API users were specifying ".coveragerc" to mean the same as
+ # True, so make it so.
+ if config_file == ".coveragerc":
+ config_file = True
specified_file = (config_file is not True)
if not specified_file:
config_file = ".coveragerc"
diff --git a/tests/test_config.py b/tests/test_config.py
index a35eb5e..58615f6 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -322,6 +322,15 @@ class ConfigFileTest(CoverageTest):
cov = coverage.coverage()
self.assert_config_settings_are_correct(cov)
+ def test_config_file_settings_in_setupcfg_if_coveragerc_specified(self):
+ # Configuration will be read from setup.cfg from sections prefixed with
+ # "coverage:", even if the API said to read from a (non-existent)
+ # .coveragerc file.
+ nested = self.LOTSA_SETTINGS.format(section="coverage:")
+ self.make_file("setup.cfg", nested + "\n" + self.SETUP_CFG)
+ cov = coverage.coverage(config_file=".coveragerc")
+ self.assert_config_settings_are_correct(cov)
+
def test_setupcfg_only_if_not_coveragerc(self):
self.make_file(".coveragerc", """\
[run]
@@ -369,3 +378,9 @@ class ConfigFileTest(CoverageTest):
msg = "Couldn't read %r as a config file" % bad_file
with self.assertRaisesRegex(CoverageException, msg):
coverage.coverage(config_file=bad_file)
+
+ def test_nocoveragerc_file_when_specified(self):
+ cov = coverage.coverage(config_file=".coveragerc")
+ self.assertFalse(cov.config.timid)
+ self.assertFalse(cov.config.branch)
+ self.assertEqual(cov.config.data_file, ".coverage")