diff options
-rw-r--r-- | coverage/config.py | 4 | ||||
-rw-r--r-- | tests/test_config.py | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/coverage/config.py b/coverage/config.py index 026f8645..7ef7e7ae 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -63,7 +63,7 @@ class HandyConfigParser(configparser.RawConfigParser): real_section = section_prefix + section if configparser.RawConfigParser.has_section(self, real_section): return configparser.RawConfigParser.options(self, real_section) - raise configparser.NoSectionError + raise configparser.NoSectionError(section) def get_section(self, section): """Get the contents of a section, as a dictionary.""" @@ -87,7 +87,7 @@ class HandyConfigParser(configparser.RawConfigParser): if configparser.RawConfigParser.has_option(self, real_section, option): break else: - raise configparser.NoOptionError + raise configparser.NoOptionError(option, section) v = configparser.RawConfigParser.get(self, real_section, option, *args, **kwargs) v = substitute_variables(v, os.environ) diff --git a/tests/test_config.py b/tests/test_config.py index f400fc17..b1611c1b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,6 +10,7 @@ import mock import pytest import coverage +from coverage.config import HandyConfigParser from coverage.misc import CoverageException from tests.coveragetest import CoverageTest, UsingModulesMixin @@ -425,6 +426,17 @@ class ConfigTest(CoverageTest): with pytest.raises(CoverageException, match=msg): _ = coverage.Coverage() + def test_exceptions_from_missing_things(self): + self.make_file("config.ini", """\ + [run] + branch = True + """) + config = HandyConfigParser("config.ini") + with pytest.raises(Exception, match="No section: 'xyzzy'"): + config.options("xyzzy") + with pytest.raises(Exception, match="No option 'foo' in section: 'xyzzy'"): + config.get("xyzzy", "foo") + class ConfigFileTest(UsingModulesMixin, CoverageTest): """Tests of the config file settings in particular.""" |