Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NameError when handling InvalidRequirement in install_req_from_req_string #6419

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6419.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix NameError when handling InvalidRequirement in install_req_from_req_string.
rouge8 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def install_req_from_req_string(
try:
req = Requirement(req_string)
except InvalidRequirement:
raise InstallationError("Invalid requirement: '%s'" % req)
raise InstallationError("Invalid requirement: '%s'" % req_string)

domains_not_allowed = [
PyPI.file_storage_domain,
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from pip._vendor.packaging.requirements import Requirement

from pip._internal.exceptions import InstallationError
from pip._internal.req.constructors import (
install_req_from_line, install_req_from_req_string,
)
Expand Down Expand Up @@ -49,6 +50,14 @@ def test_forward_slash_results_in_a_link(self, tmpdir):

class TestInstallRequirementFrom(object):

def test_install_req_from_string_invalid_requirement(self):
"""
Requirement strings that cannot be parsed by
packaging.requirements.Requirement raise an InstallationError.
"""
with pytest.raises(InstallationError):
install_req_from_req_string("http:/this/is/invalid")
rouge8 marked this conversation as resolved.
Show resolved Hide resolved

def test_install_req_from_string_without_comes_from(self):
"""
Test to make sure that install_req_from_string succeeds
Expand Down