Fix deduce_helpful_msg in python3

Add a test and changelog for #4127
This commit is contained in:
Xavier Fernandez 2017-03-23 11:36:02 +01:00 committed by Xavier Fernandez
parent 49af40e173
commit 7adacc8b18
3 changed files with 14 additions and 1 deletions

1
news/4127.feature Normal file
View File

@ -0,0 +1 @@
Improve the error message for the common ``pip install ./requirements.txt`` case.

View File

@ -1069,7 +1069,7 @@ def deduce_helpful_msg(req):
try:
with open(req, 'r') as fp:
# parse first line only
parse_requirements(fp.read()).next()
next(parse_requirements(fp.read()))
msg += " The argument you provided " + \
"(%s) appears to be a" % (req) + \
" requirements file. If that is the" + \

View File

@ -524,6 +524,18 @@ class TestInstallRequirement(object):
assert "Invalid requirement" in err_msg
assert "\nTraceback " in err_msg
def test_requirement_file(self):
req_file_path = os.path.join(self.tempdir, 'test.txt')
with open(req_file_path, 'w') as req_file:
req_file.write('pip\nsetuptools')
with pytest.raises(InstallationError) as e:
InstallRequirement.from_line(req_file_path)
err_msg = e.value.args[0]
assert "Invalid requirement" in err_msg
assert "It looks like a path. It does exist." in err_msg
assert "appears to be a requirements file." in err_msg
assert "If that is the case, use the '-r' flag to install" in err_msg
def test_requirements_data_structure_keeps_order():
requirements = Requirements()