Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for malformed pyproject.toml files #9732

Merged
merged 1 commit into from Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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