Repository navigation
Compatibility of tests with Python 3.15 #530
Copy link
Copy link
Closed
Labels
bugupstreamThis is an issue with pipdeptree's dependenciesThis is an issue with pipdeptree's dependencies
Description
What pipdeptree version are you using?
2.30.0
Are you running pipdeptree in a virtual environment?
No
Describe the problem
When running tests with Python 3.15 during build of RPM package in Fedora, we get:
=================================== FAILURES ===================================
____________________________ test_invalid_metadata _____________________________
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f18e425f450>
capfd = <_pytest.capture.CaptureFixture object at 0x7f18e4186050>
fake_dist_with_invalid_metadata = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/test_invalid_metadata0/site-packages/bar-2.4.5.dist-info')
def test_invalid_metadata(
mocker: MockerFixture, capfd: pytest.CaptureFixture[str], fake_dist_with_invalid_metadata: Path
) -> None:
fake_site_dir = str(fake_dist_with_invalid_metadata.parent)
mocked_sys_path = [fake_site_dir]
mocker.patch("pipdeptree._discovery.sys.path", mocked_sys_path)
> dists = get_installed_distributions()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_discovery.py:165:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../BUILDROOT/usr/lib/python3.15/site-packages/pipdeptree/_discovery.py:49: in get_installed_distributions
return filter_valid_distributions(distributions(path=computed_paths))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../BUILDROOT/usr/lib/python3.15/site-packages/pipdeptree/_discovery.py:89: in filter_valid_distributions
if not has_valid_metadata(dist):
^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dist = <importlib.metadata.PathDistribution object at 0x7f18e41ec640>
def has_valid_metadata(dist: Distribution) -> bool:
> return "Name" in dist.metadata
^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: argument of type 'NoneType' is not a container or iterable
../BUILDROOT/usr/lib/python3.15/site-packages/pipdeptree/_discovery.py:119: TypeError
=========================== short test summary info ============================
FAILED tests/test_discovery.py::test_invalid_metadata - TypeError: argument of type 'NoneType' is not a container or iterable
================= 1 failed, 143 passed, 7 deselected in 1.10s ==================
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugupstreamThis is an issue with pipdeptree's dependenciesThis is an issue with pipdeptree's dependencies
Activity
hroncok commentedon Jan 5, 2026
This looks like python/cpython#143387 to me.
dist.metadatais None instead of an empty dict.kemzeb commentedon Jan 8, 2026
Reading the backport changelog for v8.7.0,
metadata()and themetadataproperty now returnNoneif the METADATA file is empty or missing instead of returning an emptyPackageMetadata. Because of this, I view this as more of a breaking change since we see a change in how missing metadata is returned.Given the upstream issue opened by @hroncok, it is currently unknown what decision the Python maintainers will make so I'll keep this issue open to make sure we can track their decision and reflect it here.
Fix TypeError when dist.metadata returns None on Python 3.15
gaborbernat commentedon Mar 3, 2026
Additional finding:
has_valid_metadatain_discovery.py:119will also crash whendist.metadataisNone:With the upstream change making
metadatareturnNonefor empty/missing METADATA, this needs a guard:Additionally, downstream code at
_models/package.py:101,_discovery.py:93,145, and_freeze.py:43all dodist.metadata["Name"]directly, but those are only reached afterhas_valid_metadatapasses, so fixing the guard function should be sufficient.frenzymadness commentedon Mar 9, 2026
As far as I understand it from Jason's comments in the upstream report, no fixes are planned for this.
hroncok commentedon Mar 9, 2026
Also, I would appreciate it if anybody else but me would express their opinion about this being a breaking change in the cpython ticket. Jason decided to replace the breaking change by another breaking change in python/importlib_metadata#532
Expect dist.metadata to be None or raise an exception if invalid