Skip to content

Fix test_trailing_slash_directory_metadata for Python 3.15#13902

Merged
sbidoul merged 2 commits intopypa:mainfrom
KRRT7:fix/test-metadata-python315
Apr 12, 2026
Merged

Fix test_trailing_slash_directory_metadata for Python 3.15#13902
sbidoul merged 2 commits intopypa:mainfrom
KRRT7:fix/test-metadata-python315

Conversation

@KRRT7
Copy link
Copy Markdown
Contributor

@KRRT7 KRRT7 commented Apr 9, 2026

Summary

Python 3.15 alpha tightened importlib.metadata to raise MetadataNotFound eagerly when no metadata files exist on disk. The test used a fake non-existent path (/path/to/foo.egg-info) to verify trailing-slash handling — this worked on older Pythons where metadata access was lazy, but now fails on 3.15.

Replace the fake path with a real temp directory containing a minimal PKG-INFO file. The test still verifies the same behavior (name parsing and trailing-slash normalization).

Fixes #13901.

Test plan

  • nox -s test-3.15 -- tests/unit/metadata/test_metadata.py::test_trailing_slash_directory_metadata — 2 passed (Python 3.15.0a8)
  • nox -s test-3.12 -- tests/unit/metadata/test_metadata.py::test_trailing_slash_directory_metadata — 2 passed (Python 3.12.3)

KRRT7 added 2 commits April 8, 2026 20:23
Python 3.15 alpha tightened importlib.metadata to raise MetadataNotFound
eagerly when no metadata files exist. The test used a fake non-existent
path; replace with a real temp directory containing a minimal PKG-INFO.

Fixes pypa#13901.
@notatallshaw
Copy link
Copy Markdown
Member

Do we know what changed upstream to break this?

@KRRT7
Copy link
Copy Markdown
Contributor Author

KRRT7 commented Apr 9, 2026

CPython 3.15.0a8 intentionally changed importlib.metadata to raise MetadataNotFound when no metadata file exists, where previously it returned an empty PackageMetadata. From the 3.15.0a8 changelog:

In importlib.metadata, when a distribution file is corrupt and there is no metadata file, calls to Distribution.metadata() (including implicit calls from other properties like .name and .requires) will now raise a MetadataNotFound Exception. This allows callers to distinguish between missing metadata and a degenerate (empty) metadata.

The test was using a fake non-existent path, which worked before because accessing .metadata on a missing path silently returned empty metadata. Now it raises.

There's also a related regression tracked upstream: python/cpython#143387

@KRRT7
Copy link
Copy Markdown
Contributor Author

KRRT7 commented Apr 9, 2026

The upstream fix is python/cpython#146234 (merged). The original change that introduced MetadataNotFound came from python/importlib_metadata#532. Other projects hit the same thing — e.g., rpm-software-management/rpmlint#1488 did the same fix (add real PKG-INFO to egg-info test mocks).

@ichard26
Copy link
Copy Markdown
Member

@sbidoul this should fix failing CI on main. I haven't reviewed this yet, FWIW.

@sbidoul sbidoul added this to the 26.1 milestone Apr 11, 2026
@sbidoul
Copy link
Copy Markdown
Member

sbidoul commented Apr 12, 2026

Looks good, thanks!

@sbidoul sbidoul merged commit 2008422 into pypa:main Apr 12, 2026
36 checks passed
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_trailing_slash_directory_metadata fails on Python 3.15.0a8

4 participants