Skip to content

Commit

Permalink
Merge pull request #5923 from psinghsodhi/stopPrintSt
Browse files Browse the repository at this point in the history
Don't print stacktrace due to invalid req
  • Loading branch information
pradyunsg committed Nov 8, 2018
2 parents 3829877 + e34b19b commit 28cfd7d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/5147.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid requirement no longer causes stack trace to be printed.
3 changes: 1 addition & 2 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import logging
import os
import re
import traceback

from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
Expand Down Expand Up @@ -258,7 +257,7 @@ def install_req_from_line(
elif '=' in req and not any(op in req for op in operators):
add_msg = "= is not a valid operator. Did you mean == ?"
else:
add_msg = traceback.format_exc()
add_msg = ""
raise InstallationError(
"Invalid requirement: '%s'\n%s" % (req, add_msg)
)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@ def test_single_equal_sign(self):
assert "Invalid requirement" in err_msg
assert "= is not a valid operator. Did you mean == ?" in err_msg

def test_traceback(self):
def test_unidentifiable_name(self):
test_name = '-'
with pytest.raises(InstallationError) as e:
install_req_from_line('toto 42')
install_req_from_line(test_name)
err_msg = e.value.args[0]
assert "Invalid requirement" in err_msg
assert "\nTraceback " in err_msg
assert ("Invalid requirement: '%s'\n" % test_name) == err_msg

def test_requirement_file(self):
req_file_path = os.path.join(self.tempdir, 'test.txt')
Expand Down

0 comments on commit 28cfd7d

Please sign in to comment.