Merge pull request #9732 from nicoddemus/9730-toml-failure
Improve error message for malformed pyproject.toml files
This commit is contained in:
commit
843e01824c
|
@ -0,0 +1 @@
|
||||||
|
Malformed ``pyproject.toml`` files now produce a clearer error message.
|
|
@ -70,7 +70,7 @@ def load_config_dict_from_file(
|
||||||
try:
|
try:
|
||||||
config = tomli.loads(toml_text)
|
config = tomli.loads(toml_text)
|
||||||
except tomli.TOMLDecodeError as exc:
|
except tomli.TOMLDecodeError as exc:
|
||||||
raise UsageError(str(exc)) from exc
|
raise UsageError(f"{filepath}: {exc}") from exc
|
||||||
|
|
||||||
result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)
|
result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
|
|
|
@ -163,7 +163,17 @@ class TestParseIni:
|
||||||
pytester.path.joinpath("pytest.ini").write_text("addopts = -x")
|
pytester.path.joinpath("pytest.ini").write_text("addopts = -x")
|
||||||
result = pytester.runpytest()
|
result = pytester.runpytest()
|
||||||
assert result.ret != 0
|
assert result.ret != 0
|
||||||
result.stderr.fnmatch_lines(["ERROR: *pytest.ini:1: no section header defined"])
|
result.stderr.fnmatch_lines("ERROR: *pytest.ini:1: no section header defined")
|
||||||
|
|
||||||
|
def test_toml_parse_error(self, pytester: Pytester) -> None:
|
||||||
|
pytester.makepyprojecttoml(
|
||||||
|
"""
|
||||||
|
\\"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = pytester.runpytest()
|
||||||
|
assert result.ret != 0
|
||||||
|
result.stderr.fnmatch_lines("ERROR: *pyproject.toml: Invalid statement*")
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="probably not needed")
|
@pytest.mark.xfail(reason="probably not needed")
|
||||||
def test_confcutdir(self, pytester: Pytester) -> None:
|
def test_confcutdir(self, pytester: Pytester) -> None:
|
||||||
|
|
Loading…
Reference in New Issue