Skip to content

Commit

Permalink
fix: non-session fixtures now create their own tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahCFisher committed Feb 20, 2022
1 parent b3f69d4 commit 4e66231
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
@fixture(name="dvc_repo_session", scope="session")
def fix_dvc_repo_session() -> DvcRepo:
with tempfile.TemporaryDirectory() as dir:
this_dir = dir+"/fix_dvc_repo_session"
subprocess.check_call(["git", "init"], cwd=this_dir)
dvc = DvcRepo.init(this_dir, subdir=True)
subprocess.check_call(["git", "init"], cwd=dir)
dvc = DvcRepo.init(dir, subdir=True)
prev_dir = os.getcwd()
os.chdir(this_dir)
os.chdir(dir)

yield dvc

Expand All @@ -24,20 +23,20 @@ def fix_dvc_repo_session() -> DvcRepo:

@fixture(name="dvc_repo")
def fix_dvc_repo(dvc_repo_session) -> DvcRepo:
dvc_repo = copy.deepcopy(dvc_repo_session)
dvc_repo.root_dir += "_dvc_repo"
shutil.copytree(dvc_repo_session.root_dir, dvc_repo.root_dir)
prev_dir = os.getcwd()
os.chdir(dvc_repo.root_dir)
with tempfile.TemporaryDirectory() as dir:
dvc_repo = copy.deepcopy(dvc_repo_session)
dvc_repo.root_dir = dir
shutil.copytree(dvc_repo_session.root_dir, dvc_repo.root_dir)
prev_dir = os.getcwd()
os.chdir(dvc_repo.root_dir)

yield dvc_repo

os.chdir(prev_dir)
yield dvc_repo
os.chdir(prev_dir)

@fixture(name="empty_repo_session", scope="session")
def fix_empty_repo_session() -> str:
with tempfile.TemporaryDirectory() as dir:
this_dir = dir+"/empty_repo_session"
# Might be able to do this from python, not sure
subprocess.check_call(
f"poetry exec create-sample-project test-project sample-project-basic",
Expand All @@ -47,23 +46,24 @@ def fix_empty_repo_session() -> str:
f"mv tmp/name {dir}/tmp/name",
shell=True
)
subprocess.check_call(["git", "init"], cwd=this_dir)
subprocess.check_call(["git", "init"], cwd=dir)
prev_dir = os.getcwd()
os.chdir(this_dir)
os.chdir(dir)

yield dir

os.chdir(prev_dir)

@fixture(name="empty_repo_session")
def fix_empty_repo(empty_repo_session) -> str:
empty_repo = empty_repo_session + "_emtpy_repo"
shutil.copytree(empty_repo_session, empty_repo)
prev_dir = os.getcwd()
os.chdir(empty_repo)
with tempfile.TemporaryDirectory() as dir:
empty_repo = dir
shutil.copytree(empty_repo_session, empty_repo)
prev_dir = os.getcwd()
os.chdir(empty_repo)

yield empty_repo
yield empty_repo

os.chdir(prev_dir)
os.chdir(prev_dir)


0 comments on commit 4e66231

Please sign in to comment.