Skip to content

Commit 64faaa5

Browse files
authored
Merge pull request #9734 from pytest-dev/backport-9732-to-7.0.x
Also includes #9719
2 parents c0a03a2 + 00a163c commit 64faaa5

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

changelog/9730.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Malformed ``pyproject.toml`` files now produce a clearer error message.

src/_pytest/config/findpaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def load_config_dict_from_file(
7070
try:
7171
config = tomli.loads(toml_text)
7272
except tomli.TOMLDecodeError as exc:
73-
raise UsageError(str(exc)) from exc
73+
raise UsageError(f"{filepath}: {exc}") from exc
7474

7575
result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)
7676
if result is not None:

testing/test_config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,17 @@ def test_ini_parse_error(self, pytester: Pytester) -> None:
163163
pytester.path.joinpath("pytest.ini").write_text("addopts = -x")
164164
result = pytester.runpytest()
165165
assert result.ret != 0
166-
result.stderr.fnmatch_lines(["ERROR: *pytest.ini:1: no section header defined"])
166+
result.stderr.fnmatch_lines("ERROR: *pytest.ini:1: no section header defined")
167+
168+
def test_toml_parse_error(self, pytester: Pytester) -> None:
169+
pytester.makepyprojecttoml(
170+
"""
171+
\\"
172+
"""
173+
)
174+
result = pytester.runpytest()
175+
assert result.ret != 0
176+
result.stderr.fnmatch_lines("ERROR: *pyproject.toml: Invalid statement*")
167177

168178
@pytest.mark.xfail(reason="probably not needed")
169179
def test_confcutdir(self, pytester: Pytester) -> None:

testing/test_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ def test_valid_setup_py(self, pytester: Pytester):
803803
"""
804804
p = pytester.makepyfile(
805805
setup="""
806-
from setuptools import setup, find_packages
807806
if __name__ == '__main__':
807+
from setuptools import setup, find_packages
808808
setup(name='sample',
809809
version='0.0',
810810
description='description',

0 commit comments

Comments
 (0)