Skip to content

Commit 88ee411

Browse files
JelleZijlstraemmatyping
authored andcommitted
fix test_typed_pkg test failure on Mac (#4888)
Fixes #4883
1 parent 4649657 commit 88ee411

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

mypy/test/testpep561.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ def check_mypy_run(cmd_line: List[str],
2929
assert returncode == expected_returncode, returncode
3030

3131

32+
def is_in_venv() -> bool:
33+
"""Returns whether we are running inside a venv.
34+
35+
Based on https://stackoverflow.com/a/42580137.
36+
37+
"""
38+
if hasattr(sys, 'real_prefix'):
39+
return True
40+
else:
41+
# https://github.com/python/typeshed/pull/2047
42+
return hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix # type: ignore
43+
44+
3245
class TestPEP561(TestCase):
3346
@contextmanager
3447
def install_package(self, pkg: str,
@@ -38,9 +51,7 @@ def install_package(self, pkg: str,
3851
install_cmd = [python_executable, '-m', 'pip', 'install', '.']
3952
# if we aren't in a virtualenv, install in the
4053
# user package directory so we don't need sudo
41-
# In a virtualenv, real_prefix is patched onto
42-
# sys
43-
if not hasattr(sys, 'real_prefix') or python_executable != sys.executable:
54+
if not is_in_venv() or python_executable != sys.executable:
4455
install_cmd.append('--user')
4556
returncode, lines = run_command(install_cmd, cwd=working_dir)
4657
if returncode != 0:

0 commit comments

Comments
 (0)