test(vision): la suite non lascia piu' immagini nel repository

Il file di test dei limiti di upload scriveva un jpeg vero in
uploads/vision/reference/ a ogni esecuzione: gli mancava la fixture di
dirottamento che test_vision_reference.py ha gia'.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014BBnuACZSCJqXrMYC3LUMU
This commit is contained in:
2026-08-16 20:28:35 +02:00
parent 6bfe3a5d1a
commit f20b92bafb
@@ -21,6 +21,22 @@ from src.backend.models.orm.vision import VisionReferenceImage, VisionResult
from src.backend.tests.conftest import auth_headers, create_test_recipe from src.backend.tests.conftest import auth_headers, create_test_recipe
@pytest.fixture(autouse=True)
def redirect_uploads(monkeypatch, tmp_path):
"""Keep the reference image this file stores out of the real repo tree.
The same guard `test_vision_reference.py` carries: without it, the test that
proves a jpeg is stored with its own extension leaves a real file under
`uploads/vision/reference/`, so every suite run dirties the working tree.
`settings.upload_path` is `parents[2] / self.upload_dir`, and pathlib
replaces the left operand of `/` when the right one is absolute - so
redirecting the bare `upload_dir` setting is enough to redirect the
resolved path too.
"""
monkeypatch.setattr(settings, "upload_dir", str(tmp_path))
def a_png() -> bytes: def a_png() -> bytes:
buffer = io.BytesIO() buffer = io.BytesIO()
Image.new("L", (64, 64), color=0).save(buffer, format="PNG") Image.new("L", (64, 64), color=0).save(buffer, format="PNG")