Commit c3b4d4bc authored by Jason R. Coombs's avatar Jason R. Coombs

Extract sys.path and os.environ patching into install_target fixture

parent a2719779
......@@ -188,18 +188,19 @@ class TestUserInstallTest:
f.write('Name: foo\n')
return str(tmpdir)
@pytest.fixture()
@pytest.yield_fixture()
def install_target(self, tmpdir):
return str(tmpdir)
target = str(tmpdir)
with mock.patch('sys.path', sys.path + [target]):
python_path = os.path.pathsep.join(sys.path)
with mock.patch.dict(os.environ, PYTHONPATH=python_path):
yield target
def test_local_index(self, foo_package, install_target):
"""
The local index must be used when easy_install locates installed
packages.
"""
sys.path.append(install_target)
old_ppath = os.environ.get('PYTHONPATH')
os.environ['PYTHONPATH'] = os.path.pathsep.join(sys.path)
try:
dist = Distribution()
dist.script_name = 'setup.py'
......@@ -213,11 +214,7 @@ class TestUserInstallTest:
expected = os.path.normcase(os.path.realpath(foo_package))
assert actual == expected
finally:
sys.path.remove(install_target)
if old_ppath is not None:
os.environ['PYTHONPATH'] = old_ppath
else:
del os.environ['PYTHONPATH']
pass
@contextlib.contextmanager
def user_install_setup_context(self, *args, **kwargs):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment