diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-27 20:31:00 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-27 20:31:00 -0400 |
commit | 7470fe559f2c1fa0c6c87365f115f27c6a4d6ff7 (patch) | |
tree | c196528b61f50c4b961cc7be7000138e9a60ce3a /coverage/config.py | |
parent | 5e944cc789a6f068b8ce4fbc255e4d9bfcd72c5f (diff) | |
download | python-coveragepy-git-7470fe559f2c1fa0c6c87365f115f27c6a4d6ff7.tar.gz |
Fail on unrecognized configuration options. #386
Diffstat (limited to 'coverage/config.py')
-rw-r--r-- | coverage/config.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/coverage/config.py b/coverage/config.py index edcf13e8..9939d6c0 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -3,7 +3,11 @@ """Config file for coverage.py""" -import os, re, sys +import collections +import os +import re +import sys + from coverage.backward import configparser, iitems, string_class from coverage.misc import CoverageException @@ -221,6 +225,23 @@ class CoverageConfig(object): except ValueError as err: raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) + # Check that there are no unrecognized options. + all_options = collections.defaultdict(set) + for option_spec in self.CONFIG_FILE_OPTIONS: + section, option = option_spec[1].split(":") + all_options[section].add(option) + + for section, options in iitems(all_options): + if cp.has_section(section): + for unknown in set(cp.options(section)) - options: + if section_prefix: + section = section_prefix + section + raise CoverageException( + "Unrecognized option '[%s] %s=' in config file %s" % ( + section, unknown, filename + ) + ) + # [paths] is special if cp.has_section('paths'): for option in cp.options('paths'): |