Skip to content

Commit 4bc2480

Browse files
committed
Merge pull request pypa#3205 from xavfernandez/traceback_format_exc
Fix traceback.format_exc call
2 parents f23cbb7 + 0cc9d73 commit 4bc2480

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

pip/req/req_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ def setup_py(self):
344344
assert self.source_dir, "No source dir for %s" % self
345345
try:
346346
import setuptools # noqa
347-
except ImportError as e:
347+
except ImportError:
348348
if get_installed_version('setuptools') is None:
349349
add_msg = "Please install setuptools."
350350
else:
351-
add_msg = traceback.format_exc(e)
351+
add_msg = traceback.format_exc()
352352
# Setuptools is not available
353353
raise InstallationError(
354354
"Could not import setuptools which is required to "

tests/functional/test_install.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ def test_without_setuptools(script, data):
3030
"source distribution."
3131
in result.stderr
3232
)
33+
assert "Please install setuptools" in result.stderr
34+
35+
36+
def test_with_setuptools_and_import_error(script, data):
37+
# Make sure we get an ImportError while importing setuptools
38+
setuptools_init_path = script.site_packages_path.join(
39+
"setuptools", "__init__.py")
40+
with open(setuptools_init_path, 'a') as f:
41+
f.write('\nraise ImportError("toto")')
42+
43+
result = script.run(
44+
"python", "-c",
45+
"import pip; pip.main(["
46+
"'install', "
47+
"'INITools==0.2', "
48+
"'-f', '%s', "
49+
"'--no-binary=:all:'])" % data.packages,
50+
expect_error=True,
51+
)
52+
assert (
53+
"Could not import setuptools which is required to install from a "
54+
"source distribution."
55+
in result.stderr
56+
)
57+
assert "Traceback " in result.stderr
58+
assert "ImportError: toto" in result.stderr
3359

3460

3561
def test_pip_second_command_line_interface_works(script, data):

0 commit comments

Comments
 (0)