mirror of https://github.com/pypa/pip
Isolate our tests from the running user's configuration
This commit is contained in:
parent
6fdb9bdce7
commit
97d8bee705
|
@ -75,8 +75,8 @@ else
|
|||
sudo pip install virtualenv
|
||||
fi
|
||||
|
||||
git config --global user.email "python-virtualenv@googlegroups.com"
|
||||
git config --global user.name "Pip"
|
||||
git config --global user.email "pypa-dev@googlegroups.com"
|
||||
git config --global user.name "pip"
|
||||
|
||||
virtualenv ~/.venv
|
||||
source ~/.venv/bin/activate
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
import py
|
||||
|
@ -32,6 +33,58 @@ def tmpdir(request):
|
|||
return Path(str(tmp))
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def isolate(tmpdir):
|
||||
"""
|
||||
Isolate our tests so that things like global configuration files and the
|
||||
like do not affect our test results.
|
||||
|
||||
We use an autouse function scoped fixture because we want to ensure that
|
||||
every test has it's own isolated home directory.
|
||||
"""
|
||||
# TODO: Ensure Windows will respect $HOME, including for the cache
|
||||
# directory
|
||||
|
||||
# TODO: Figure out how to isolate from *system* level configuration files
|
||||
# as well as user level configuration files.
|
||||
|
||||
# Create a directory to use as our home location.
|
||||
home_dir = os.path.join(str(tmpdir), "home")
|
||||
os.makedirs(home_dir)
|
||||
|
||||
# Create a directory to use as a fake root
|
||||
fake_root = os.path.join(str(tmpdir), "fake-root")
|
||||
os.makedirs(fake_root)
|
||||
|
||||
# Set our home directory to our temporary directory, this should force all
|
||||
# of our relative configuration files to be read from here instead of the
|
||||
# user's actual $HOME directory.
|
||||
os.environ["HOME"] = home_dir
|
||||
|
||||
# Isolate ourselves from XDG directories
|
||||
os.environ["XDG_DATA_HOME"] = os.path.join(home_dir, ".local", "share")
|
||||
os.environ["XDG_CONFIG_HOME"] = os.path.join(home_dir, ".config")
|
||||
os.environ["XDG_CACHE_HOME"] = os.path.join(home_dir, ".cache")
|
||||
os.environ["XDG_RUNTIME_DIR"] = os.path.join(home_dir, ".runtime")
|
||||
os.environ["XDG_DATA_DIRS"] = ":".join([
|
||||
os.path.join(fake_root, "usr", "local", "share"),
|
||||
os.path.join(fake_root, "usr", "share"),
|
||||
])
|
||||
os.environ["XDG_CONFIG_DIRS"] = os.path.join(fake_root, "etc", "xdg")
|
||||
|
||||
# Configure git, because without an author name/email git will complain
|
||||
# and cause test failures.
|
||||
os.environ["GIT_CONFIG_NOSYSTEM"] = "1"
|
||||
os.environ["GIT_AUTHOR_NAME"] = "pip"
|
||||
os.environ["GIT_AUTHOR_EMAIL"] = "pypa-dev@googlegroups.com"
|
||||
|
||||
os.makedirs(os.path.join(home_dir, ".config", "git"))
|
||||
with open(os.path.join(home_dir, ".config", "git", "config"), "wb") as fp:
|
||||
fp.write(
|
||||
b"[user]\n\tname = pip\n\temail = pypa-dev@googlegroups.com\n"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def virtualenv(tmpdir, monkeypatch):
|
||||
"""
|
||||
|
|
|
@ -448,7 +448,7 @@ setup(name='version_subpkg',
|
|||
script.run('git', 'add', '.', cwd=version_pkg_path)
|
||||
script.run(
|
||||
'git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'initial version', cwd=version_pkg_path
|
||||
)
|
||||
|
||||
|
@ -476,7 +476,7 @@ def _create_test_package(script):
|
|||
script.run('git', 'add', '.', cwd=version_pkg_path)
|
||||
script.run(
|
||||
'git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'initial version', cwd=version_pkg_path,
|
||||
)
|
||||
return version_pkg_path
|
||||
|
@ -493,7 +493,7 @@ def _change_test_package_version(script, version_pkg_path):
|
|||
)
|
||||
script.run(
|
||||
'git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'messed version',
|
||||
cwd=version_pkg_path,
|
||||
expect_stderr=True,
|
||||
|
|
|
@ -10,7 +10,7 @@ def _create_test_package_submodule(env):
|
|||
env.run('git', 'init', cwd=submodule_path)
|
||||
env.run('git', 'add', '.', cwd=submodule_path)
|
||||
env.run('git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'initial version / submodule', cwd=submodule_path)
|
||||
return submodule_path
|
||||
|
||||
|
@ -20,7 +20,7 @@ def _change_test_package_submodule(env, submodule_path):
|
|||
submodule_path.join("testfile2").write("this is an added file")
|
||||
env.run('git', 'add', '.', cwd=submodule_path)
|
||||
env.run('git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'submodule change', cwd=submodule_path)
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ def _pull_in_submodule_changes_to_module(env, module_path):
|
|||
cwd=module_path / 'testpkg/static/',
|
||||
)
|
||||
env.run('git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'submodule change', cwd=module_path)
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ def _create_test_package_with_submodule(env):
|
|||
env.run('git', 'init', cwd=version_pkg_path, expect_error=True)
|
||||
env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True)
|
||||
env.run('git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'initial version', cwd=version_pkg_path,
|
||||
expect_error=True)
|
||||
|
||||
|
@ -75,7 +75,7 @@ def _create_test_package_with_submodule(env):
|
|||
expect_error=True,
|
||||
)
|
||||
env.run('git', 'commit', '-q',
|
||||
'--author', 'Pip <python-virtualenv@googlegroups.com>',
|
||||
'--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'-am', 'initial version w submodule', cwd=version_pkg_path,
|
||||
expect_error=True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue