Improve output when parsing an ini configuration fails (#5650)

Improve output when parsing an ini configuration fails
This commit is contained in:
Bruno Oliveira 2019-07-23 11:17:42 -03:00 committed by GitHub
commit 52ad5a1591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 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,12 @@ 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")