SACC / tests /helpers.py
cacode's picture
Deploy updated SCU course catcher
e28c9e4 verified
raw
history blame contribute delete
560 Bytes
from __future__ import annotations
import shutil
import uuid
from contextlib import contextmanager
from pathlib import Path
from typing import Iterator
@contextmanager
def workspace_tempdir(prefix: str) -> Iterator[Path]:
base_dir = Path(__file__).resolve().parent.parent / "data" / "test-artifacts"
base_dir.mkdir(parents=True, exist_ok=True)
temp_dir = base_dir / f"{prefix}{uuid.uuid4().hex}"
temp_dir.mkdir(parents=True, exist_ok=True)
try:
yield temp_dir
finally:
shutil.rmtree(temp_dir, ignore_errors=True)