Merge pull request #9734 from pytest-dev/backport-9732-to-7.0.x

Also includes https://github.com/pytest-dev/pytest/pull/9719
This commit is contained in:
Bruno Oliveira 2022-03-06 15:19:09 -03:00 committed by GitHub
commit 64faaa5e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

View File

@ -0,0 +1 @@
Malformed ``pyproject.toml`` files now produce a clearer error message.

View File

@ -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:

View File

@ -163,7 +163,17 @@ class TestParseIni:
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:

View File

@ -803,8 +803,8 @@ class TestDoctests:
"""
p = pytester.makepyfile(
setup="""
from setuptools import setup, find_packages
if __name__ == '__main__':
from setuptools import setup, find_packages
setup(name='sample',
version='0.0',
description='description',