From 400393cfe4f45b3a8c6b89bbbb4041797dd3bc61 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 23 Jul 2019 11:17:42 -0300 Subject: [PATCH] Improve output when parsing an ini configuration fails (#5650) Improve output when parsing an ini configuration fails --- changelog/5650.bugfix.rst | 1 + src/_pytest/config/findpaths.py | 6 +++++- testing/test_config.py | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelog/5650.bugfix.rst diff --git a/changelog/5650.bugfix.rst b/changelog/5650.bugfix.rst new file mode 100644 index 000000000..db57a40b9 --- /dev/null +++ b/changelog/5650.bugfix.rst @@ -0,0 +1 @@ +Improved output when parsing an ini configuration file fails. diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index 3ece3bdc1..e6779b289 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -33,7 +33,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 diff --git a/testing/test_config.py b/testing/test_config.py index 0678a0d90..7cf37bf30 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -131,6 +131,12 @@ class TestParseIni(object): 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")