Skip to content

Commit

Permalink
test: Use context manager for tmp dirs (flyteorg#2922)
Browse files Browse the repository at this point in the history
Signed-off-by: JiaWei Jiang <[email protected]>
Signed-off-by: 400Ping <[email protected]>
  • Loading branch information
JiangJiaWei1103 authored and 400Ping committed Nov 22, 2024
1 parent fed5c5e commit 7f09f2f
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions tests/flytekit/unit/types/directory/test_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@

@pytest.fixture
def local_tmp_dirs():
# Create a source directory
src_dir = tempfile.TemporaryDirectory()
for file_idx in range(N_FILES_PER_DIR):
with open(Path(src_dir.name) / f"{file_idx}.txt", "w") as f:
f.write(str(file_idx))

# Create an empty directory as the destination
dst_dir = tempfile.TemporaryDirectory()

yield src_dir.name, dst_dir.name
# Create a source and an empty destination directory
with (tempfile.TemporaryDirectory() as src_dir,
tempfile.TemporaryDirectory() as dst_dir):
for file_idx in range(N_FILES_PER_DIR):
with open(Path(src_dir) / f"{file_idx}.txt", "w") as f:
f.write(str(file_idx))

# Cleanup
src_dir.cleanup()
dst_dir.cleanup()
yield src_dir, dst_dir


def test_src_path_with_different_types(local_tmp_dirs) -> None:
Expand Down

0 comments on commit 7f09f2f

Please sign in to comment.