abinazebinoy commited on
Commit
a39e4a7
·
1 Parent(s): 0ec385b

Tests: Mark ML model tests as slow for faster CI

Browse files

Marked slow tests (@pytest .mark.slow):
- test_dire_detector.py: All tests (loads Stable Diffusion ~30s)
- test_clip_detector.py: All tests (loads CLIP model ~10s)
- test_clip_database.py: All tests (processes reference images)

Updated CI workflow:
- Run fast tests first (~2 min)
- Run slow tests separately (can be skipped locally)

Usage:
- Fast only: pytest -m 'not slow'
- Slow only: pytest -m 'slow'
- All tests: pytest

Closes #43

.github/workflows/ci.yml CHANGED
@@ -55,6 +55,12 @@ jobs:
55
  pip-audit || true
56
  continue-on-error: true
57
 
58
- - name: Run tests
59
  run: |
60
- pytest backend/tests/ -v --tb=short
 
 
 
 
 
 
 
55
  pip-audit || true
56
  continue-on-error: true
57
 
58
+ - name: Run fast tests
59
  run: |
60
+ pytest backend/tests/ -v -m "not slow" --tb=short
61
+
62
+ - name: Run slow tests (ML models)
63
+ if: success()
64
+ run: |
65
+ pytest backend/tests/ -v -m "slow" --tb=short
66
+ continue-on-error: true
backend/tests/test_clip_database.py CHANGED
@@ -4,7 +4,7 @@ Tests for CLIP reference database.
4
  import pytest
5
  from pathlib import Path
6
 
7
-
8
  def test_clip_database_exists():
9
  """Test that CLIP database file exists."""
10
  database_path = Path("data/reference/clip_database.pkl")
@@ -16,7 +16,7 @@ def test_clip_database_exists():
16
  else:
17
  pytest.skip("CLIP database not built yet. Run: python scripts/build_clip_database.py")
18
 
19
-
20
  def test_clip_detector_loads_database():
21
  """Test that CLIP detector loads reference database."""
22
  from backend.services.clip_detector import CLIPDetector
@@ -37,7 +37,7 @@ def test_clip_detector_loads_database():
37
 
38
  detector.cleanup()
39
 
40
-
41
  def test_clip_detection_with_database(sample_image_bytes):
42
  """Test CLIP detection uses database."""
43
  from backend.services.clip_detector import CLIPDetector
 
4
  import pytest
5
  from pathlib import Path
6
 
7
+ @pytest.mark.slow
8
  def test_clip_database_exists():
9
  """Test that CLIP database file exists."""
10
  database_path = Path("data/reference/clip_database.pkl")
 
16
  else:
17
  pytest.skip("CLIP database not built yet. Run: python scripts/build_clip_database.py")
18
 
19
+ @pytest.mark.slow
20
  def test_clip_detector_loads_database():
21
  """Test that CLIP detector loads reference database."""
22
  from backend.services.clip_detector import CLIPDetector
 
37
 
38
  detector.cleanup()
39
 
40
+ @pytest.mark.slow
41
  def test_clip_detection_with_database(sample_image_bytes):
42
  """Test CLIP detection uses database."""
43
  from backend.services.clip_detector import CLIPDetector
backend/tests/test_clip_detector.py CHANGED
@@ -3,7 +3,7 @@ Tests for CLIP detector.
3
  """
4
  import pytest
5
 
6
-
7
  def test_clip_detector_initialization():
8
  """Test CLIP detector can be initialized."""
9
  from backend.services.clip_detector import CLIPDetector
@@ -12,7 +12,7 @@ def test_clip_detector_initialization():
12
  assert detector is not None
13
  assert detector.device in ["cuda", "cpu"]
14
 
15
-
16
  def test_clip_detection_on_sample(sample_image_bytes):
17
  """Test CLIP detection on sample image."""
18
  from backend.services.clip_detector import CLIPDetector
@@ -35,7 +35,7 @@ def test_clip_detection_on_sample(sample_image_bytes):
35
  # Cleanup
36
  detector.cleanup()
37
 
38
-
39
  def test_clip_handles_errors_gracefully():
40
  """Test CLIP handles corrupted input gracefully."""
41
  from backend.services.clip_detector import CLIPDetector
 
3
  """
4
  import pytest
5
 
6
+ @pytest.mark.slow
7
  def test_clip_detector_initialization():
8
  """Test CLIP detector can be initialized."""
9
  from backend.services.clip_detector import CLIPDetector
 
12
  assert detector is not None
13
  assert detector.device in ["cuda", "cpu"]
14
 
15
+ @pytest.mark.slow
16
  def test_clip_detection_on_sample(sample_image_bytes):
17
  """Test CLIP detection on sample image."""
18
  from backend.services.clip_detector import CLIPDetector
 
35
  # Cleanup
36
  detector.cleanup()
37
 
38
+ @pytest.mark.slow
39
  def test_clip_handles_errors_gracefully():
40
  """Test CLIP handles corrupted input gracefully."""
41
  from backend.services.clip_detector import CLIPDetector
backend/tests/test_dire_detector.py CHANGED
@@ -5,7 +5,7 @@ import pytest
5
  from PIL import Image
6
  import io
7
 
8
-
9
  def test_dire_detector_initialization():
10
  """Test DIRE detector initializes correctly."""
11
  from backend.services.dire_detector import DIREDetector
@@ -17,7 +17,7 @@ def test_dire_detector_initialization():
17
  assert detector._model_loaded == False
18
  assert detector.cache_key == "stable-diffusion-2-1"
19
 
20
-
21
  def test_dire_detection_on_sample(sample_image_bytes):
22
  """Test DIRE detection on sample image."""
23
  from backend.services.dire_detector import DIREDetector
@@ -34,7 +34,7 @@ def test_dire_detection_on_sample(sample_image_bytes):
34
 
35
  detector.cleanup()
36
 
37
-
38
  def test_dire_handles_errors_gracefully():
39
  """Test DIRE handles invalid input gracefully."""
40
  from backend.services.dire_detector import DIREDetector
 
5
  from PIL import Image
6
  import io
7
 
8
+ @pytest.mark.slow
9
  def test_dire_detector_initialization():
10
  """Test DIRE detector initializes correctly."""
11
  from backend.services.dire_detector import DIREDetector
 
17
  assert detector._model_loaded == False
18
  assert detector.cache_key == "stable-diffusion-2-1"
19
 
20
+ @pytest.mark.slow
21
  def test_dire_detection_on_sample(sample_image_bytes):
22
  """Test DIRE detection on sample image."""
23
  from backend.services.dire_detector import DIREDetector
 
34
 
35
  detector.cleanup()
36
 
37
+ @pytest.mark.slow
38
  def test_dire_handles_errors_gracefully():
39
  """Test DIRE handles invalid input gracefully."""
40
  from backend.services.dire_detector import DIREDetector