Skip to content

Compatibility of tests with Python 3.15 #530

Closed

Description

@frenzymadness

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 ==================

Activity

  1. hroncok commented on Jan 5, 2026

    @hroncok
    Contributor

    This looks like python/cpython#143387 to me. dist.metadata is None instead of an empty dict.

  2. self-assigned this
    on Jan 5, 2026
  3. kemzeb commented on Jan 8, 2026

    @kemzeb
    Collaborator

    Reading the backport changelog for v8.7.0, metadata() and the metadata property now return None if the METADATA file is empty or missing instead of returning an empty PackageMetadata. 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.

  4. added
    upstreamThis is an issue with pipdeptree's dependencies
    and removed
    tobeconfirmedTo be confirmed after more investigation
    on Jan 8, 2026
  5. added a commit that references this issue on Feb 17, 2026
    880e59f
  6. gaborbernat commented on Mar 3, 2026

    @gaborbernat
    Member

    Additional finding: has_valid_metadata in _discovery.py:119 will also crash when dist.metadata is None:

    def has_valid_metadata(dist: Distribution) -> bool:
        return "Name" in dist.metadata  # TypeError: argument of type 'NoneType' is not iterable

    With the upstream change making metadata return None for empty/missing METADATA, this needs a guard:

    def has_valid_metadata(dist: Distribution) -> bool:
        return dist.metadata is not None and "Name" in dist.metadata

    Additionally, downstream code at _models/package.py:101, _discovery.py:93,145, and _freeze.py:43 all do dist.metadata["Name"] directly, but those are only reached after has_valid_metadata passes, so fixing the guard function should be sufficient.

  7. frenzymadness commented on Mar 9, 2026

    @frenzymadness
    ContributorAuthor

    As far as I understand it from Jason's comments in the upstream report, no fixes are planned for this.

  8. hroncok commented on Mar 9, 2026

    @hroncok
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugupstreamThis is an issue with pipdeptree's dependencies

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions