summaryrefslogtreecommitdiff
path: root/setuptools/tests/config/test_pyprojecttoml.py
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-04 12:50:55 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-04 12:58:56 +0100
commit9f57e702cd420d9bd198b17cf1b52541a641903d (patch)
treea83b1e5315ad4e769eec16d44284992a8bea39fc /setuptools/tests/config/test_pyprojecttoml.py
parent3181239daa400715896f2cac42e9f6ee2a500163 (diff)
downloadpython-setuptools-git-9f57e702cd420d9bd198b17cf1b52541a641903d.tar.gz
Improve pyproject.toml validation messages
Based on the following discussions: - https://github.com/pypa/packaging.python.org/pull/1031#issuecomment-1127214128 - https://github.com/pypa/packaging-problems/issues/604 it seems that people are having a hard time finding information about validation error due to the long traceback and debug info. The idea behind this change is to make the most relevant information to fix the error easier to spot.
Diffstat (limited to 'setuptools/tests/config/test_pyprojecttoml.py')
-rw-r--r--setuptools/tests/config/test_pyprojecttoml.py23
1 files changed, 5 insertions, 18 deletions
diff --git a/setuptools/tests/config/test_pyprojecttoml.py b/setuptools/tests/config/test_pyprojecttoml.py
index 200312b5..811328f5 100644
--- a/setuptools/tests/config/test_pyprojecttoml.py
+++ b/setuptools/tests/config/test_pyprojecttoml.py
@@ -1,4 +1,3 @@
-import logging
import re
from configparser import ConfigParser
from inspect import cleandoc
@@ -307,7 +306,7 @@ def test_ignore_unrelated_config(tmp_path, example):
@pytest.mark.parametrize(
- "example, error_msg, value_shown_in_debug",
+ "example, error_msg",
[
(
"""
@@ -316,30 +315,18 @@ def test_ignore_unrelated_config(tmp_path, example):
version = "1.2"
requires = ['pywin32; platform_system=="Windows"' ]
""",
- "configuration error: `project` must not contain {'requires'} properties",
- '"requires": ["pywin32; platform_system==\\"Windows\\""]',
+ "configuration error: .project. must not contain ..requires.. properties",
),
],
)
-def test_invalid_example(tmp_path, caplog, example, error_msg, value_shown_in_debug):
- caplog.set_level(logging.DEBUG)
+def test_invalid_example(tmp_path, example, error_msg):
pyproject = tmp_path / "pyproject.toml"
pyproject.write_text(cleandoc(example))
- caplog.clear()
- with pytest.raises(ValueError, match="invalid pyproject.toml"):
+ pattern = re.compile(f"invalid pyproject.toml.*{error_msg}.*", re.M | re.S)
+ with pytest.raises(ValueError, match=pattern):
read_configuration(pyproject)
- # Make sure the logs give guidance to the user
- error_log = caplog.record_tuples[0]
- assert error_log[1] == logging.ERROR
- assert error_msg in error_log[2]
-
- debug_log = caplog.record_tuples[1]
- assert debug_log[1] == logging.DEBUG
- debug_msg = "".join(line.strip() for line in debug_log[2].splitlines())
- assert value_shown_in_debug in debug_msg
-
@pytest.mark.parametrize("config", ("", "[tool.something]\nvalue = 42"))
def test_empty(tmp_path, config):