diff --git a/news/5147.bugfix b/news/5147.bugfix new file mode 100644 index 00000000000..59f3846e9dc --- /dev/null +++ b/news/5147.bugfix @@ -0,0 +1 @@ +Invalid requirement no longer causes stack trace to be printed. diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 4c4641dc883..ad1c9109617 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -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 @@ -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) ) diff --git a/tests/unit/test_req.py b/tests/unit/test_req.py index 10a20b7ac50..47b96c400f7 100644 --- a/tests/unit/test_req.py +++ b/tests/unit/test_req.py @@ -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')