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 /coverage/config.py | |
parent | 929dfc31c84d34aab9a25ca507e3a7dba9a7723d (diff) | |
download | python-coveragepy-8c19329691ba161715c8f7b464ff1f080f3e3671.tar.gz |
Make sure that an uninterested setup.cfg doesn't prevent tox.ini from working
Diffstat (limited to 'coverage/config.py')
-rw-r--r-- | coverage/config.py | 25 |
1 files changed, 21 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`.""" |