Skip optional-dependency test modules instead of erroring at collection#142
Open
rogerSuperBuilderAlpha wants to merge 2 commits into
Open
Conversation
`test_cache.py` and `test_parallel.py` import `redis` and `ray` at module
scope. These are optional dependencies (the `caching` and `parallel` extras),
so on any environment without them installed a plain `pytest` run aborts during
collection:
ModuleNotFoundError: No module named 'ray'
which masks the rest of the suite. Use `pytest.importorskip` so the modules skip
cleanly when the dependency is absent, while still running in full where the
extras are installed (e.g. CI).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
test/test_cache.pyandtest/test_parallel.pyimport their optional dependencies at module scope:redisandrayare optional extras (cachingandparallel). On any environment that doesn't have them installed, a plainpytestrun aborts during collection:Because collection errors are fatal, this masks the entire rest of the suite for a contributor who installed only
.[dev].Change
Use
pytest.importorskipfor the optional imports so the modules skip cleanly when the dependency is missing, while still running fully where the extras are installed (e.g. CI):Verification
pytest --conow collects the full suite with no collection errors (previously 4), and the two modules report asskippedrather thanerror.redis/rayare installed, behavior is unchanged (the import resolves and the tests run as before).