Skip to content

Commit 2f2f8e5

Browse files
emmatypingilevkivskyi
authored andcommitted
Give error if we failed to create the virtualenv (#5237)
1 parent 8aebf0b commit 2f2f8e5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mypy/test/testpep561.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ def virtualenv(self,
4949
"""Context manager that creates a virtualenv in a temporary directory
5050
5151
returns the path to the created Python executable"""
52+
# Sadly, we need virtualenv, as the Python 3 venv module does not support creating a venv
53+
# for Python 2, and Python 2 does not have its own venv.
5254
with tempfile.TemporaryDirectory() as venv_dir:
53-
run_command([sys.executable, '-m', 'virtualenv', '-p{}'.format(python_executable),
54-
venv_dir], cwd=os.getcwd())
55+
returncode, lines = run_command([sys.executable,
56+
'-m',
57+
'virtualenv',
58+
'-p{}'.format(python_executable),
59+
venv_dir], cwd=os.getcwd())
60+
if returncode != 0:
61+
err = '\n'.join(lines)
62+
self.fail("Failed to create venv. Do you have virtualenv installed?\n" + err)
5563
if sys.platform == 'win32':
5664
yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python'))
5765
else:

0 commit comments

Comments
 (0)