2023-10-13 17:56:10 +00:00
|
|
|
import os
|
2023-07-28 10:12:37 +00:00
|
|
|
import tempfile
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Iterator
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def temporary_dir() -> Iterator[Path]:
|
2023-10-13 17:56:10 +00:00
|
|
|
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)
|