Skip to content

Commit 8c47db7

Browse files
committed
Improve output when parsing an ini configuration fails
1 parent 693e9d0 commit 8c47db7

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

changelog/5650.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved output when parsing an ini configuration file fails.

src/_pytest/config/findpaths.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def getcfg(args, config=None):
3232
for inibasename in inibasenames:
3333
p = base.join(inibasename)
3434
if exists(p):
35-
iniconfig = py.iniconfig.IniConfig(p)
35+
try:
36+
iniconfig = py.iniconfig.IniConfig(p)
37+
except py.iniconfig.ParseError as exc:
38+
raise UsageError(str(exc))
39+
3640
if (
3741
inibasename == "setup.cfg"
3842
and "tool:pytest" in iniconfig.sections

testing/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ def test_toxini_before_lower_pytestini(self, testdir):
122122
config = testdir.parseconfigure(sub)
123123
assert config.getini("minversion") == "2.0"
124124

125+
def test_ini_parse_error(self, testdir):
126+
testdir.tmpdir.join("pytest.ini").write('addopts = -x')
127+
result = testdir.runpytest()
128+
assert result.ret != 0
129+
result.stderr.fnmatch_lines([
130+
"ERROR: *pytest.ini:1: no section header defined"
131+
])
132+
125133
@pytest.mark.xfail(reason="probably not needed")
126134
def test_confcutdir(self, testdir):
127135
sub = testdir.mkdir("sub")

0 commit comments

Comments
 (0)