mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Fix NameError when handling InvalidRequirement in install_req_from_req_string (#6419)
Previously, an InvalidRequirement would raise a NameError while trying to raise an InstallationError because `req` was not defined. Discovered while working on #6402.
This commit is contained in:
parent
c8e9caa8a7
commit
bb14ff42b0
3 changed files with 15 additions and 1 deletions
1
news/6419.bugfix
Normal file
1
news/6419.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix ``NameError`` when handling an invalid requirement.
|
|
@ -319,7 +319,7 @@ def install_req_from_req_string(
|
||||||
try:
|
try:
|
||||||
req = Requirement(req_string)
|
req = Requirement(req_string)
|
||||||
except InvalidRequirement:
|
except InvalidRequirement:
|
||||||
raise InstallationError("Invalid requirement: '%s'" % req)
|
raise InstallationError("Invalid requirement: '%s'" % req_string)
|
||||||
|
|
||||||
domains_not_allowed = [
|
domains_not_allowed = [
|
||||||
PyPI.file_storage_domain,
|
PyPI.file_storage_domain,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import tempfile
|
||||||
import pytest
|
import pytest
|
||||||
from pip._vendor.packaging.requirements import Requirement
|
from pip._vendor.packaging.requirements import Requirement
|
||||||
|
|
||||||
|
from pip._internal.exceptions import InstallationError
|
||||||
from pip._internal.req.constructors import (
|
from pip._internal.req.constructors import (
|
||||||
install_req_from_line, install_req_from_req_string,
|
install_req_from_line, install_req_from_req_string,
|
||||||
)
|
)
|
||||||
|
@ -49,6 +50,18 @@ class TestInstallRequirementBuildDirectory(object):
|
||||||
|
|
||||||
class TestInstallRequirementFrom(object):
|
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) as excinfo:
|
||||||
|
install_req_from_req_string("http:/this/is/invalid")
|
||||||
|
|
||||||
|
assert str(excinfo.value) == (
|
||||||
|
"Invalid requirement: 'http:/this/is/invalid'"
|
||||||
|
)
|
||||||
|
|
||||||
def test_install_req_from_string_without_comes_from(self):
|
def test_install_req_from_string_without_comes_from(self):
|
||||||
"""
|
"""
|
||||||
Test to make sure that install_req_from_string succeeds
|
Test to make sure that install_req_from_string succeeds
|
||||||
|
|
Loading…
Reference in a new issue