summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-02-25 20:32:34 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-02-25 20:32:34 -0500
commit198a11535b5065416c41e7fdc025718c1a92eff3 (patch)
tree95ed70625ce48a1a55556b13fe84973359177a81
parent1bdf48368c37bfe2de866e51133b240fda6eda36 (diff)
downloadpython-coveragepy-git-198a11535b5065416c41e7fdc025718c1a92eff3.tar.gz
test: add a test of missing sections and options
-rw-r--r--coverage/config.py4
-rw-r--r--tests/test_config.py12
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."""