Repository navigation
Add opt-in deferred dependency gates to importorskip - #15340
Open
Dhruv-Sharma29 wants to merge 1 commit into
Open
Dhruv-Sharma29 wants to merge 1 commit into
Dhruv-Sharma29 wants to merge 1 commit into
Conversation
Dhruv-Sharma29
marked this pull request as ready for review
November 5, 2026 12:02
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This branch has not been deployed
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
A module-level
pytest.importorskip()currently stops collection when an optional dependency is unavailable. Individual tests and parametrizations behind that gate are absent from--collect-onlyand per-test reports.Proposed behavior
Add the opt-in
defer=Trueparameter:During test-module or conftest import, record the missing or too-old dependency as a scoped gate and return an unavailable-module stand-in. Allow collection to finish, then skip each affected item at setup before fixtures execute. Preserve the original reason and gate location in skip reports. A conftest gate applies only to tests under that directory.
If eager dependency use or a subsequent exception prevents completing the gated import, fall back to the original module-level skip. Inside tests or fixtures, skip immediately as before. Calls without
defer=Truekeep the existing behavior.Closes #15267
Implementation
Validation
git diff --checkpassed.Design review
This is a draft implementation of the proposal, pending agreement on the public API and fallback semantics. The rest of a gated module executes, so import-time side effects are possible. Successful deferred collection changes skip counts from one per module to one per test. The stand-in is neither a real module nor
None.This does not introduce the optional companion
requires_importmarker. The documentation'sversionaddedentry assumes 9.2 and can be adjusted to the intended release.AI assistance was used to prepare this change. I have reviewed the diff, understand its behavior, and take responsibility for responding substantively to maintainer feedback.