diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/config.py | 16 | ||||
-rw-r--r-- | coverage/control.py | 24 |
2 files changed, 25 insertions, 15 deletions
diff --git a/coverage/config.py b/coverage/config.py index 9598f74d..65f4222a 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -197,14 +197,24 @@ class CoverageConfig(object): self.attempted_config_files.append(filename) cp = HandyConfigParser(section_prefix) - files_read = cp.read(filename) + try: + files_read = cp.read(filename) + except configparser.Error as err: + raise CoverageException( + "Couldn't read config file %s: %s" % (filename, err) + ) if not files_read: return False self.config_files.extend(files_read) - for option_spec in self.CONFIG_FILE_OPTIONS: - self._set_attr_from_config_option(cp, *option_spec) + try: + for option_spec in self.CONFIG_FILE_OPTIONS: + self._set_attr_from_config_option(cp, *option_spec) + except ValueError as err: + raise CoverageException( + "Couldn't read config file %s: %s" % (filename, err) + ) # [paths] is special if cp.has_section('paths'): diff --git a/coverage/control.py b/coverage/control.py index 815c16b9..6aa06da8 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -94,20 +94,20 @@ class Coverage(object): # 1: defaults: self.config = CoverageConfig() - # 2: from the .coveragerc or setup.cfg file: + # 2: from the rcfile, .coveragerc or setup.cfg file: if config_file: - did_read_rc = should_read_setupcfg = False - if config_file is True: + did_read_rc = False + specified_file = (config_file is not True) + if not specified_file: config_file = ".coveragerc" - should_read_setupcfg = True - try: - did_read_rc = self.config.from_file(config_file) - except ValueError as err: - raise CoverageException( - "Couldn't read config file %s: %s" % (config_file, err) - ) - - if not did_read_rc and should_read_setupcfg: + + did_read_rc = self.config.from_file(config_file) + + if not did_read_rc: + if specified_file: + raise CoverageException( + "Couldn't read %r as a config file" % config_file + ) self.config.from_file("setup.cfg", section_prefix="coverage:") # 3: from environment variables: |