Improve output when parsing an ini configuration fails

This commit is contained in:
Florian Bruhin 2019-07-23 15:24:22 +02:00
parent 693e9d0733
commit 8c47db724c
3 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1 @@
Improved output when parsing an ini configuration file fails.

View File

@ -32,7 +32,11 @@ def getcfg(args, config=None):
for inibasename in inibasenames:
p = base.join(inibasename)
if exists(p):
iniconfig = py.iniconfig.IniConfig(p)
try:
iniconfig = py.iniconfig.IniConfig(p)
except py.iniconfig.ParseError as exc:
raise UsageError(str(exc))
if (
inibasename == "setup.cfg"
and "tool:pytest" in iniconfig.sections

View File

@ -122,6 +122,14 @@ class TestParseIni:
config = testdir.parseconfigure(sub)
assert config.getini("minversion") == "2.0"
def test_ini_parse_error(self, testdir):
testdir.tmpdir.join("pytest.ini").write('addopts = -x')
result = testdir.runpytest()
assert result.ret != 0
result.stderr.fnmatch_lines([
"ERROR: *pytest.ini:1: no section header defined"
])
@pytest.mark.xfail(reason="probably not needed")
def test_confcutdir(self, testdir):
sub = testdir.mkdir("sub")