Skip to content

Commit

Permalink
Test: editable install \w --user&build isolation
Browse files Browse the repository at this point in the history
Add a new test and confirm that it
fails in the expected manner
  • Loading branch information
hexagonrecursion committed Mar 6, 2022
1 parent 6376ad1 commit e977837
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
from . import contexts
from .textwrap import DALS

import py


@pytest.fixture(autouse=True)
def pip_disable_index(monkeypatch):
Expand Down Expand Up @@ -1109,3 +1111,43 @@ def test_use_correct_python_version_string(tmpdir, tmpdir_cwd, monkeypatch):
assert cmd.config_vars['py_version'] == '3.10.1'
assert cmd.config_vars['py_version_short'] == '3.10'
assert cmd.config_vars['py_version_nodot'] == '310'


def test_editable_install_honors_user_under_build_isolation(setup_context, monkeypatch, tmpdir):
''' `setup.py develop` should honor `--user` even under build isolation'''

## Arrange:
# Pretend that build isolation was enabled
# e.g pip sets the environment varible PYTHONNOUSERSITE=1
monkeypatch.setattr('site.ENABLE_USER_SITE', False)

# Patching $HOME for 2 reasons:
# 1. setuptools/command/easy_install.py:create_home_path
# tries creating directories in $HOME
# given `self.config_vars['DESTDIRS'] = "/home/user/.pyenv/versions/3.9.10 /home/user/.pyenv/versions/3.9.10/lib /home/user/.pyenv/versions/3.9.10/lib/python3.9 /home/user/.pyenv/versions/3.9.10/lib/python3.9/lib-dynload"``
# it will `makedirs("/home/user/.pyenv/versions/3.9.10 /home/user/.pyenv/versions/3.9.10/lib /home/user/.pyenv/versions/3.9.10/lib/python3.9 /home/user/.pyenv/versions/3.9.10/lib/python3.9/lib-dynload")``
# 2. We are going to force `site` to update site.USER_BASE and site.USER_SITE
# To point inside our new home
monkeypatch.setenv('HOME', str(tmpdir / 'home'))
monkeypatch.setattr('site.USER_BASE', None)
monkeypatch.setattr('site.USER_SITE', None)
user_site = py.path.local(site.getusersitepackages())
user_site.ensure_dir()

sys_prefix = (tmpdir / 'sys_prefix').ensure_dir()
monkeypatch.setattr('sys.prefix', str(sys_prefix))

## Sanity check:
assert sys_prefix.listdir() == []
assert user_site.listdir() == []

## Act:
run_setup('setup.py', ['develop', '--user'])

## Assert:
# Should not install to sys.prefix
with pytest.raises(AssertionError):
assert sys_prefix.listdir() == []
# Should install to user site
with pytest.raises(AssertionError):
assert {f.basename for f in user_site.listdir()} == {'UNKNOWN.egg-link'}

0 comments on commit e977837

Please sign in to comment.