diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-19 17:46:52 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-19 17:46:52 -0500 |
commit | 8c19329691ba161715c8f7b464ff1f080f3e3671 (patch) | |
tree | 5e84929918b350f679f269255c5e0b8a14dcdac8 | |
parent | 929dfc31c84d34aab9a25ca507e3a7dba9a7723d (diff) | |
download | python-coveragepy-8c19329691ba161715c8f7b464ff1f080f3e3671.tar.gz |
Make sure that an uninterested setup.cfg doesn't prevent tox.ini from working
-rw-r--r-- | coverage/config.py | 25 | ||||
-rw-r--r-- | tests/test_config.py | 9 |
2 files changed, 30 insertions, 4 deletions
diff --git a/coverage/config.py b/coverage/config.py index d6f5af0..663bc64 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -207,7 +207,8 @@ class CoverageConfig(object): `filename` is a file name to read. - Returns True or False, whether the file could be read. + Returns True or False, whether the file could be read, and it had some + coverage.py settings in it. """ self.attempted_config_files.append(filename) @@ -222,9 +223,12 @@ class CoverageConfig(object): self.config_files.extend(files_read) + any_set = False try: for option_spec in self.CONFIG_FILE_OPTIONS: - self._set_attr_from_config_option(cp, *option_spec) + was_set = self._set_attr_from_config_option(cp, *option_spec) + if was_set: + any_set = True except ValueError as err: raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) @@ -249,13 +253,20 @@ class CoverageConfig(object): if cp.has_section('paths'): for option in cp.options('paths'): self.paths[option] = cp.getlist('paths', option) + any_set = True # plugins can have options for plugin in self.plugins: if cp.has_section(plugin): self.plugin_options[plugin] = cp.get_section(plugin) + any_set = True - return True + # Was this file used as a config file? If no prefix, then it was used. + # If a prefix, then it was only used if we found some settings in it. + if section_prefix: + return any_set + else: + return True CONFIG_FILE_OPTIONS = [ # These are *args for _set_attr_from_config_option: @@ -304,11 +315,17 @@ class CoverageConfig(object): ] def _set_attr_from_config_option(self, cp, attr, where, type_=''): - """Set an attribute on self if it exists in the ConfigParser.""" + """Set an attribute on self if it exists in the ConfigParser. + + Returns True if the attribute was set. + + """ section, option = where.split(":") if cp.has_option(section, option): method = getattr(cp, 'get' + type_) setattr(self, attr, method(section, option)) + return True + return False def get_plugin_options(self, plugin): """Get a dictionary of options for the plugin named `plugin`.""" diff --git a/tests/test_config.py b/tests/test_config.py index cff9b60..6cb5e46 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -426,6 +426,15 @@ class ConfigFileTest(CoverageTest): def test_toxini_only_if_prefixed(self): self.check_other_config_need_prefixes("tox.ini") + def test_tox_ini_even_if_setup_cfg(self): + # There's a setup.cfg, but no coverage settings in it, so tox.ini + # is read. + nested = self.LOTSA_SETTINGS.format(section="coverage:") + self.make_file("tox.ini", self.TOX_INI + "\n" + nested) + self.make_file("setup.cfg", self.SETUP_CFG) + cov = coverage.Coverage() + self.assert_config_settings_are_correct(cov) + def test_non_ascii(self): self.make_file(".coveragerc", """\ [report] |