Skip to content

Commit 829941a

Browse files
authored
[4.6] Improve output when parsing an ini configuration fails (#… (#5652)
[4.6] Improve output when parsing an ini configuration fails (#5650)
2 parents 459c5f4 + 2e345fd commit 829941a

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ env:
1313
global:
1414
- PYTEST_ADDOPTS=-vv
1515

16+
# setuptools-scm needs all tags in order to obtain a proper version
17+
git:
18+
depth: false
19+
1620
install:
1721
- python -m pip install --upgrade --pre tox
1822

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
@@ -33,7 +33,11 @@ def getcfg(args, config=None):
3333
for inibasename in inibasenames:
3434
p = base.join(inibasename)
3535
if exists(p):
36-
iniconfig = py.iniconfig.IniConfig(p)
36+
try:
37+
iniconfig = py.iniconfig.IniConfig(p)
38+
except py.iniconfig.ParseError as exc:
39+
raise UsageError(str(exc))
40+
3741
if (
3842
inibasename == "setup.cfg"
3943
and "tool:pytest" in iniconfig.sections

testing/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def test_toxini_before_lower_pytestini(self, testdir):
131131
config = testdir.parseconfigure(sub)
132132
assert config.getini("minversion") == "2.0"
133133

134+
def test_ini_parse_error(self, testdir):
135+
testdir.tmpdir.join("pytest.ini").write("addopts = -x")
136+
result = testdir.runpytest()
137+
assert result.ret != 0
138+
result.stderr.fnmatch_lines(["ERROR: *pytest.ini:1: no section header defined"])
139+
134140
@pytest.mark.xfail(reason="probably not needed")
135141
def test_confcutdir(self, testdir):
136142
sub = testdir.mkdir("sub")

0 commit comments

Comments
 (0)