Skip to content

handle PEP 639 License-Expression in test metadata#46

Merged
thrau merged 1 commit intolocalstack:mainfrom
nolith:fix/pep639-license-metadata
Apr 2, 2026
Merged

handle PEP 639 License-Expression in test metadata#46
thrau merged 1 commit intolocalstack:mainfrom
nolith:fix/pep639-license-metadata

Conversation

@nolith
Copy link
Copy Markdown
Contributor

@nolith nolith commented Apr 2, 2026

Problem

test_resolve_distribution_information asserts dist.metadata["License"] == "MIT" against the installed pytest package. This fails when pytest is built with PEP 639 metadata (setuptools >= 77), because the License header no longer exists — it is replaced by License-Expression.

Why upstream CI doesn't catch it

The dev dependencies pin pytest==8.4.1, which was built with older setuptools and still has the legacy License: MIT header in its METADATA. The test only fails with pytest >= 9.0, which requires setuptools>=77 and emits PEP 639 metadata (License-Expression: MIT with no License field).

Any environment that doesn't use the pinned pytest version (e.g. nixpkgs, conda, other distros) hits this failure.

Fix

Use .get() to check License-Expression first, then fall back to License. This handles both old-style and PEP 639 metadata:

license_value = dist.metadata.get("License-Expression") or dist.metadata.get("License")
assert license_value == "MIT"

Using .get() instead of [] also avoids the DeprecationWarning from importlib.metadata about implicit None returns on missing keys, which will become a KeyError in a future Python version.

pytest >= 9.0 is built with setuptools >= 77, which emits
License-Expression instead of the legacy License header.
Use .get() to support both old-style and PEP 639 metadata.

AI-assisted: OpenCode (Claude Opus 4.6)
@nolith nolith requested review from dfangl and thrau as code owners April 2, 2026 10:21
@nolith
Copy link
Copy Markdown
Contributor Author

nolith commented Apr 2, 2026

I didn't go as far as upgrading pytest, but on a local test I can confirm the entire test suite works with pytest-9.0.2

. .venv/bin/activate && python -m pytest
============================= test session starts ==============================
platform darwin -- Python 3.13.12, pytest-9.0.2, pluggy-1.6.0
rootdir: /Users/nolith/src/nix/plux
configfile: pyproject.toml
collected 47 items
tests/cli/test_discover.py ......                                        [ 12%]
tests/cli/test_entrypoints.py .........                                  [ 31%]
tests/cli/test_hatchling.py ...                                          [ 38%]
tests/runtime/test_cache.py ..                                           [ 42%]
tests/runtime/test_resolve.py .                                          [ 44%]
tests/test_discovery.py ..                                               [ 48%]
tests/test_entrypoint.py ...                                             [ 55%]
tests/test_function_plugin.py ...                                        [ 61%]
tests/test_listener.py ....                                              [ 70%]
tests/test_manager.py .............                                      [ 97%]
tests/test_metadata.py .                                                 [100%]
============================= 47 passed in 15.21s ==============================

Copy link
Copy Markdown
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch Alessio @nolith, thanks for the contribution!

this change looks good to me. i would also have been ok with just removing the assert. but this makes it much clearer. i was vaguely aware that the license metadata field had been changed, but hadn't connected the dots to plux, so thanks!

@thrau thrau merged commit 13be7ab into localstack:main Apr 2, 2026
5 checks passed
@nolith nolith deleted the fix/pep639-license-metadata branch April 2, 2026 10:38
github-merge-queue bot pushed a commit to NixOS/nixpkgs that referenced this pull request Apr 3, 2026
test_resolve_distribution_information fails with pytest >= 9.0.2 because
pytest now uses PEP 639 License-Expression metadata instead of the legacy
License field. Upstream pins pytest==8.4.1 in CI and has not encountered
this yet.

Upstream fix: localstack/plux#46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants