Skip to content

Commit

Permalink
Improve output when parsing an ini configuration fails (#5650)
Browse files Browse the repository at this point in the history
Improve output when parsing an ini configuration fails
  • Loading branch information
nicoddemus authored Jul 23, 2019
2 parents 693e9d0 + a82dd2f commit 52ad5a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/5650.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved output when parsing an ini configuration file fails.
6 changes: 5 additions & 1 deletion src/_pytest/config/findpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def test_toxini_before_lower_pytestini(self, testdir):
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")
Expand Down

0 comments on commit 52ad5a1

Please sign in to comment.