From e977837e8c8a0f593b559e3f02d8229e52bb7899 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sat, 5 Mar 2022 18:22:01 +0300 Subject: [PATCH] Test: editable install \w --user&build isolation Add a new test and confirm that it fails in the expected manner --- setuptools/tests/test_easy_install.py | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 5831b26757a..a51a488d1c8 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -40,6 +40,8 @@ from . import contexts from .textwrap import DALS +import py + @pytest.fixture(autouse=True) def pip_disable_index(monkeypatch): @@ -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'}