Skip to content

fix(tests): skip packaging test gracefully when setuptools is absent - #35050

Closed
teknium1 wants to merge 1 commit into
mainfrom
fix/packaging-test-setuptools-guard
Closed

fix(tests): skip packaging test gracefully when setuptools is absent#35050
teknium1 wants to merge 1 commit into
mainfrom
fix/packaging-test-setuptools-guard

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

tests/test_packaging_metadata.py no longer fails the whole test slice when setuptools isn't installed.

Root cause

The module imported from setuptools import find_packages at the top level. setuptools is only a build-system requirement ([build-system].requires in pyproject.toml), not a runtime or test dependency. In lean test environments that install only runtime + dev deps (some CI slices, slim containers), setuptools may be absent — and the module-level import then raised ModuleNotFoundError at collection time, which failed the entire test (N) slice and took the other three packaging tests (faster-whisper, MANIFEST, plugin-manifest) down with it, even though they never use setuptools.

Observed on the slice-1 shard: 4795 tests passed, 0 failed, but the slice still exited 1 because of this single collection error.

Changes

  • tests/test_packaging_metadata.py:
    • Detect availability via importlib.util.find_spec("setuptools") at module level (no import, no collection error).
    • Gate the one test that needs find_packages behind @pytest.mark.skipif.
    • Defer the actual from setuptools import find_packages into the test body.

Validation

Before After
setuptools present 4 passed 4 passed
setuptools absent collection error → whole slice fails 1 skipped, 3 passed

tests/test_packaging_metadata.py imported 'from setuptools import find_packages'
at module top level. setuptools is only a build-system requirement
([build-system].requires), not a runtime/test dependency, so lean test
environments (some CI slices, slim containers) may not have it installed.

When absent, the module-level import raised ModuleNotFoundError at COLLECTION
time, which failed the entire test slice — taking the other three packaging
tests (faster-whisper, MANIFEST, plugin-manifest) down with it even though
they don't need setuptools.

Fix: detect availability via importlib.util.find_spec at module level (no
import error), gate the one test that needs find_packages behind
@pytest.mark.skipif, and defer the actual import into the test body. The
other three tests now run regardless.
@teknium1

Copy link
Copy Markdown
Contributor Author

Superseded by #34851, which landed on main a few minutes before this and fixes the same root cause two ways: declares setuptools==82.0.1 in the [dev] extra AND guards the import with pytest.importorskip. Closing as redundant.

@teknium1 teknium1 closed this May 30, 2026
@teknium1
teknium1 deleted the fix/packaging-test-setuptools-guard branch May 30, 2026 00:31
@alt-glitch alt-glitch added type/test Test coverage or test infrastructure P3 Low — cosmetic, nice to have labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants