Kaynağa Gözat

Fix plate detection calibration persistence

- Check cv2.imwrite() return value to catch silent failures
- Verify reference image file exists after save
- Validate file size is reasonable (>1KB) to detect corruption
- Add logging for save, rotate, and delete operations
- Use temp directory for plate calibration during tests to avoid
  deleting real user calibration files

Previously, calibration could report success even if the image file
failed to save. Additionally, running tests would delete real
calibration files because tests shared the same plate_calibration_dir.
maziggy 7 ay önce
ebeveyn
işleme
c196ae017a
1 değiştirilmiş dosya ile 17 ekleme ve 0 silme
  1. 17 0
      backend/tests/conftest.py

+ 17 - 0
backend/tests/conftest.py

@@ -1,12 +1,16 @@
 """Shared test fixtures for BamBuddy backend tests."""
 """Shared test fixtures for BamBuddy backend tests."""
 
 
 import asyncio
 import asyncio
+import atexit
 import json
 import json
 import logging
 import logging
 import os
 import os
+import shutil
 import sys
 import sys
+import tempfile
 from collections.abc import AsyncGenerator
 from collections.abc import AsyncGenerator
 from datetime import datetime
 from datetime import datetime
+from pathlib import Path
 from unittest.mock import AsyncMock, MagicMock, patch
 from unittest.mock import AsyncMock, MagicMock, patch
 
 
 import pytest
 import pytest
@@ -24,6 +28,19 @@ from backend.app.core.config import settings  # noqa: E402
 
 
 settings.log_to_file = False
 settings.log_to_file = False
 
 
+# Use a temp directory for plate calibration to avoid deleting real calibration files
+_test_plate_cal_dir = Path(tempfile.mkdtemp(prefix="bambuddy_test_plate_cal_"))
+settings.plate_calibration_dir = _test_plate_cal_dir
+
+
+# Clean up temp directory when tests finish
+def _cleanup_test_plate_cal_dir():
+    if _test_plate_cal_dir.exists():
+        shutil.rmtree(_test_plate_cal_dir, ignore_errors=True)
+
+
+atexit.register(_cleanup_test_plate_cal_dir)
+
 from backend.app.core.database import Base  # noqa: E402
 from backend.app.core.database import Base  # noqa: E402
 
 
 # Use in-memory SQLite for tests
 # Use in-memory SQLite for tests