Checklist
Safety version
3.6.2 (also present on main as of today — verified against tests/conftest.py on main)
Python version
3.11
Operating System
Linux (openEuler RPM buildroot / chroot, but any environment with a broken .dist-info is affected)
Bug description
When running the test suite with pytest, pytest_configure in tests/conftest.py iterates over all installed distributions in the environment:
def pytest_configure(config):
main_deps_specs = get_project_dependencies()
all_dists = {
canonicalize_name(dist.metadata["Name"]): (dist.metadata["Name"], dist.version)
for dist in distributions()
}
This assumes every installed distribution has a Name field in its metadata. In an RPM buildroot (and other non-venv environments), some .dist-info directories lack the Name entry, so dist.metadata["Name"] returns None and packaging.utils.canonicalize_name(None) raises AttributeError — pytest aborts with INTERNALERROR before any test runs, so the whole %check stage of the package build fails.
This is only printed as a dependency table (informational output), but it hard-crashes the test session in environments where the system site-packages contain a partially-installed or malformed distribution.
Steps to reproduce
In an environment where at least one installed distribution has a .dist-info without a Name: field in METADATA (easy to hit inside a chroot/buildroot), run:
Command and output
INTERNALERROR> File "/home/lkp/rpmbuild/BUILD/safety-3.6.2/tests/conftest.py", line 52, in pytest_configure
INTERNALERROR> all_dists = {
INTERNALERROR> File "/home/lkp/rpmbuild/BUILD/safety-3.6.2/tests/conftest.py", line 53, in <dictcomp>
INTERNALERROR> canonicalize_name(dist.metadata["Name"]): (dist.metadata["Name"], dist.version)
INTERNALERROR> File "/usr/lib/python3.11/site-packages/packaging/utils.py", line 120, in canonicalize_name
INTERNALERROR> value = name.lower().replace("_", "-").replace(".", "-")
INTERNALERROR> ^^^^^^^^^^
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'lower'
error: Bad exit status from /var/tmp/rpm-tmp.8Zhikk (%check)
Additional context
Suggested fix
Skip distributions without a Name:
all_dists = {
canonicalize_name(name): (name, dist.version)
for dist in distributions()
if (name := dist.metadata["Name"]) is not None
}
Checklist
Safety version
3.6.2 (also present on
mainas of today — verified againsttests/conftest.pyonmain)Python version
3.11
Operating System
Linux (openEuler RPM buildroot / chroot, but any environment with a broken .dist-info is affected)
Bug description
When running the test suite with pytest,
pytest_configureintests/conftest.pyiterates over all installed distributions in the environment:This assumes every installed distribution has a
Namefield in its metadata. In an RPM buildroot (and other non-venv environments), some.dist-infodirectories lack theNameentry, sodist.metadata["Name"]returnsNoneandpackaging.utils.canonicalize_name(None)raisesAttributeError— pytest aborts withINTERNALERRORbefore any test runs, so the whole %check stage of the package build fails.This is only printed as a dependency table (informational output), but it hard-crashes the test session in environments where the system site-packages contain a partially-installed or malformed distribution.
Steps to reproduce
In an environment where at least one installed distribution has a
.dist-infowithout aName:field inMETADATA(easy to hit inside a chroot/buildroot), run:Command and output
Additional context
Suggested fix
Skip distributions without a
Name: