Use fixtures instead of TempDirectory in test_vcs_git.py.
@@ -6,7 +6,6 @@ import os
import pytest
-from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.vcs.git import Git
from tests.lib import _create_test_package, _git_commit, _test_path_to_file_url
@@ -39,32 +38,35 @@ def check_rev(repo_dir, rev, expected):
assert git.get_revision_sha(repo_dir, rev) == expected
-def test_git_dir_ignored():
+def test_git_dir_ignored(tmpdir):
"""
Test that a GIT_DIR environment variable is ignored.
"""
- git = Git()
- with TempDirectory() as temp:
- temp_dir = temp.path
+ repo_path = tmpdir / 'test-repo'
+ repo_path.mkdir()
+ repo_dir = str(repo_path)
+
env = {'GIT_DIR': 'foo'}
# If GIT_DIR is not ignored, then os.listdir() will return ['foo'].
- git.run_command(['init', temp_dir], cwd=temp_dir, extra_environ=env)
- assert os.listdir(temp_dir) == ['.git']
+ Git().run_command(['init', repo_dir], cwd=repo_dir, extra_environ=env)
+ assert os.listdir(repo_dir) == ['.git']
-def test_git_work_tree_ignored():
+def test_git_work_tree_ignored(tmpdir):
"""
Test that a GIT_WORK_TREE environment variable is ignored.
"""
+ repo_path = tmpdir / 'test-repo'
+ repo_path.mkdir()
+ repo_dir = str(repo_path)
+
git = Git()
- with TempDirectory() as temp:
- temp_dir = temp.path
- git.run_command(['init', temp_dir], cwd=temp_dir)
+ git.run_command(['init', repo_dir], cwd=repo_dir)
# Choose a directory relative to the cwd that does not exist.
# If GIT_WORK_TREE is not ignored, then the command will error out
# with: "fatal: This operation must be run in a work tree".
env = {'GIT_WORK_TREE': 'foo'}
- git.run_command(['status', temp_dir], extra_environ=env, cwd=temp_dir)
+ git.run_command(['status', repo_dir], extra_environ=env, cwd=repo_dir)
def test_get_remote_url(script, tmpdir):
@@ -83,8 +85,9 @@ def test_get_remote_url(script, tmpdir):
assert remote_url == source_url
-def test_get_branch(script, tmpdir):
- repo_dir = str(tmpdir)
+def test_get_branch(script):
+ repo_dir = str(script.scratch_path)
+
script.run('git', 'init', cwd=repo_dir)
sha = do_commit(script, repo_dir)
@@ -105,8 +108,8 @@ def test_get_branch(script, tmpdir):
def test_get_revision_sha(script):
- with TempDirectory(kind="testing") as temp:
- repo_dir = temp.path
+ repo_dir = str(script.scratch_path)
+
script.run('git', 'init', cwd=repo_dir)
shas = add_commits(script, repo_dir, count=3)
