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

Fix uninformative error message #830

Merged
merged 4 commits into from
Sep 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/packaging/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,12 @@ def _process_dynamic(self, value: list[str]) -> list[str]:
for dynamic_field in map(str.lower, value):
if dynamic_field in {"name", "version", "metadata-version"}:
raise self._invalid_metadata(
f"{value!r} is not allowed as a dynamic field"
f"{dynamic_field!r} is not allowed as a dynamic field"
)
elif dynamic_field not in _EMAIL_TO_RAW_MAPPING:
raise self._invalid_metadata(f"{value!r} is not a valid dynamic field")
raise self._invalid_metadata(
f"{dynamic_field!r} is not a valid dynamic field"
)
return list(map(str.lower, value))

def _process_provides_extra(
Expand Down
6 changes: 5 additions & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,12 @@ def test_invalid_dynamic_value(self):
def test_disallowed_dynamic(self, field_name):
meta = metadata.Metadata.from_raw({"dynamic": [field_name]}, validate=False)

with pytest.raises(metadata.InvalidMetadata):
message = f"{field_name!r} is not allowed"
with pytest.raises(metadata.InvalidMetadata, match=message) as execinfo:
meta.dynamic # noqa: B018
# The name of the specific offending field should be used,
# not a list with all fields:
assert "[" not in str(execinfo.value)

@pytest.mark.parametrize(
"field_name",
Expand Down
Loading