Skip to content

Skip optional-dependency test modules instead of erroring at collection#142

Open
rogerSuperBuilderAlpha wants to merge 2 commits into
wmayner:feature/iit-4.0from
rogerSuperBuilderAlpha:fix/optional-dep-test-collection
Open

Skip optional-dependency test modules instead of erroring at collection#142
rogerSuperBuilderAlpha wants to merge 2 commits into
wmayner:feature/iit-4.0from
rogerSuperBuilderAlpha:fix/optional-dep-test-collection

Conversation

@rogerSuperBuilderAlpha
Copy link
Copy Markdown

Problem

test/test_cache.py and test/test_parallel.py import their optional dependencies at module scope:

import redis   # test_cache.py
import ray      # test_parallel.py

redis and ray are optional extras (caching and parallel). On any environment that doesn't have them installed, a plain pytest run aborts during collection:

ERROR test/test_parallel.py - ModuleNotFoundError: No module named 'ray'
ERROR test/test_cache.py
!!!!!!!!!!!!!!!!!!! Interrupted: errors 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.importorskip for 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):

redis = pytest.importorskip("redis")
ray = pytest.importorskip("ray")

Verification

  • With neither extra installed, pytest --co now collects the full suite with no collection errors (previously 4), and the two modules report as skipped rather than error.
  • Where redis/ray are installed, behavior is unchanged (the import resolves and the tests run as before).

rogerSuperBuilderAlpha and others added 2 commits May 30, 2026 11:27
`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant