Skip to content

Commit

Permalink
Merge pull request #9732 from nicoddemus/9730-toml-failure
Browse files Browse the repository at this point in the history
Improve error message for malformed pyproject.toml files
  • Loading branch information
asottile committed Mar 6, 2022
2 parents bc43d66 + e38d1ca commit 843e018
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/9730.bugfix.rst
@@ -0,0 +1 @@
Malformed ``pyproject.toml`` files now produce a clearer error message.
2 changes: 1 addition & 1 deletion src/_pytest/config/findpaths.py
Expand Up @@ -70,7 +70,7 @@ def load_config_dict_from_file(
try:
config = tomli.loads(toml_text)
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)
if result is not None:
Expand Down
12 changes: 11 additions & 1 deletion testing/test_config.py
Expand Up @@ -163,7 +163,17 @@ def test_ini_parse_error(self, pytester: Pytester) -> None:
pytester.path.joinpath("pytest.ini").write_text("addopts = -x")
result = pytester.runpytest()
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")
def test_confcutdir(self, pytester: Pytester) -> None:
Expand Down

0 comments on commit 843e018

Please sign in to comment.