Skip to content

fix test_typed_pkg test failure on Mac #4888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ def check_mypy_run(cmd_line: List[str],
assert returncode == expected_returncode, returncode


def is_in_venv() -> bool:
"""Returns whether we are running inside a venv.

Based on https://stackoverflow.com/a/42580137.

"""
if hasattr(sys, 'real_prefix'):
return True
else:
# https://github.com/python/typeshed/pull/2047
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged that typeshed PR, but yet another typeshed sync is also needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that we'd just merge this to get mypy master back in a good state. I can send another small PR to remove the type ignore later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Actually I propose not to cp that onto the release branch, since the # type: ignore below silences the error. We can fix things on the master branch.)

return hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix # type: ignore


class TestPEP561(TestCase):
@contextmanager
def install_package(self, pkg: str,
Expand All @@ -38,9 +51,7 @@ def install_package(self, pkg: str,
install_cmd = [python_executable, '-m', 'pip', 'install', '.']
# if we aren't in a virtualenv, install in the
# user package directory so we don't need sudo
# In a virtualenv, real_prefix is patched onto
# sys
if not hasattr(sys, 'real_prefix') or python_executable != sys.executable:
if not is_in_venv() or python_executable != sys.executable:
install_cmd.append('--user')
returncode, lines = run_command(install_cmd, cwd=working_dir)
if returncode != 0:
Expand Down