diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2014-12-29 23:40:30 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-12-29 23:40:30 -0500 |
commit | dce270b4271ad6607c28103c9199303121b52015 (patch) | |
tree | 8e6bd938e03c767dc027cc7db9ab29d7174fbbf6 | |
parent | 12169497ccb2303474016e01933f52d7e4eab93a (diff) | |
download | external_python_setuptools-dce270b4271ad6607c28103c9199303121b52015.tar.gz external_python_setuptools-dce270b4271ad6607c28103c9199303121b52015.tar.bz2 external_python_setuptools-dce270b4271ad6607c28103c9199303121b52015.zip |
Make sure to monkey-patch the easy_install module in the setup context. Fixes the other former test failure. Ref #315.
-rwxr-xr-x | setup.py | 1 | ||||
-rw-r--r-- | setuptools/tests/test_easy_install.py | 24 |
2 files changed, 25 insertions, 0 deletions
@@ -210,6 +210,7 @@ setup_params = dict( tests_require=[ 'setuptools[ssl]', 'pytest', + 'mock', ], setup_requires=[ ] + pytest_runner, diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 530f89f3..546fa750 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -13,7 +13,9 @@ import logging import distutils.core import pytest +import mock +from setuptools import sandbox from setuptools.compat import StringIO, BytesIO, urlparse from setuptools.sandbox import run_setup, SandboxViolation from setuptools.command.easy_install import ( @@ -227,6 +229,27 @@ class TestUserInstallTest(unittest.TestCase): else: del os.environ['PYTHONPATH'] + @contextlib.contextmanager + def user_install_setup_context(self, *args, **kwargs): + """ + Wrap sandbox.setup_context to patch easy_install in that context to + appear as user-installed. + """ + with self.orig_context(*args, **kwargs): + import setuptools.command.easy_install as ei + ei.__file__ = site.USER_SITE + yield + + + def patched_setup_context(self): + self.orig_context = sandbox.setup_context + + return mock.patch( + 'setuptools.sandbox.setup_context', + self.user_install_setup_context, + ) + + def test_setup_requires(self): """Regression test for Distribute issue #318 @@ -241,6 +264,7 @@ class TestUserInstallTest(unittest.TestCase): try: with quiet_context(): with reset_setup_stop_context(): + with self.patched_setup_context(): run_setup(test_setup_py, ['install']) except SandboxViolation: self.fail('Installation caused SandboxViolation') |