Improve error message when discovery plugin is not available - #3032
Merged
Conversation
gaborbernat
approved these changes
Feb 15, 2026
gaborbernat
enabled auto-merge (squash)
February 15, 2026 05:13
gaborbernat
requested changes
Feb 15, 2026
gaborbernat
left a comment
Contributor
There was a problem hiding this comment.
You'll need to rebase to fix merge conflcits.
auto-merge was automatically disabled
February 16, 2026 00:13
Head branch was pushed to by a user without write access
veeceey
force-pushed
the
fix/issue-2896-error-message
branch
from
February 16, 2026 00:13
7dbe318 to
229c13a
Compare
When VIRTUALENV_DISCOVERY is set via environment variable to a plugin that isn't installed, the previous behavior was a raw KeyError which was confusing and unhelpful. Now raises a RuntimeError with a clear message showing the requested plugin name, available discovery methods, and a hint to check if the plugin is installed. Fixes pypa#2896
The test_invalid_discovery_method_via_env test was expecting a ValueError with the old error format from PR pypa#3031, but our changes raise a RuntimeError with improved messaging. Update the test assertions to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
veeceey
force-pushed
the
fix/issue-2896-error-message
branch
from
February 16, 2026 02:55
fbfedc3 to
20fc4d2
Compare
This was referenced Mar 12, 2026
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.
When
VIRTUALENV_DISCOVERYis set via environment variable to a plugin that isn't installed, the previous behavior was a rawKeyError:This was confusing, especially for users running virtualenv through tox where the full traceback made it hard to understand the actual problem.
Now it raises a clear
RuntimeErrorwith a helpful message:Note that when
--discoveryis passed as a CLI argument, argparse already validates the choice and gives a reasonable error. This fix covers the env var (and ini config) code path where the value bypasses argparse's choice validation since it's set as a default.Fixes #2896