clan-core/pkgs/clan-cli/tests/temporary_dir.py
2023-10-27 19:11:27 +02:00

19 lines
476 B
Python

import os
import tempfile
from pathlib import Path
from typing import Iterator
import pytest
@pytest.fixture
def temporary_dir() -> Iterator[Path]:
if os.getenv("TEST_KEEP_TEMPORARY_DIR"):
temp_dir = tempfile.mkdtemp(prefix="pytest-")
path = Path(temp_dir)
yield path
print("=========> Keeping temporary directory: ", path)
else:
with tempfile.TemporaryDirectory(prefix="pytest-") as dirpath:
yield Path(dirpath)