Skip to content

Commit

Permalink
test: Use context manager for tmp dirs (#2922)
Browse files Browse the repository at this point in the history
Signed-off-by: JiaWei Jiang <[email protected]>
  • Loading branch information
JiangJiaWei1103 authored Nov 12, 2024
1 parent f09c536 commit a6d6335
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 a6d6335

Please sign in to comment.