aipluto-backend / tests /conftest.py
andreskoenig's picture
deploy from cli
104aa46 verified
Raw
History Blame Contribute Delete
854 Bytes
import io
import urllib.request
from pathlib import Path
import pytest
from PIL import Image
# A public-domain dog photo from Wikimedia (Golden Retriever). Cached after first run.
_DOG_URL = (
"https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/"
"American_Eskimo_Dog_1.jpg/640px-American_Eskimo_Dog_1.jpg"
)
_CACHE = Path("/tmp/test_dog.jpg")
@pytest.fixture(scope="session")
def dog_image() -> Image.Image:
if not _CACHE.exists():
try:
req = urllib.request.Request(_DOG_URL, headers={"User-Agent": "find-my-dog/0.1"})
with urllib.request.urlopen(req, timeout=30) as resp:
_CACHE.write_bytes(resp.read())
except Exception as exc: # noqa: BLE001
pytest.skip(f"Could not fetch test dog image: {exc}")
return Image.open(io.BytesIO(_CACHE.read_bytes())).copy()