Skip to content

Commit bfbcbd9

Browse files
committed
Moved multiprocessing test fixture, and skipped tests if on win32 sys.
1 parent 2d8abc6 commit bfbcbd9

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

backend/tests/unit/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88

99
from app.services import ActivePipelineService, MetricsService
1010

11-
# @pytest.fixture(scope="session", autouse=True)
12-
# def set_multiprocessing_start_method():
13-
# # Set multiprocessing start method to 'fork' to ensure mocked objects and patches
14-
# # from the parent process are inherited by child processes. The default 'spawn'
15-
# # method creates isolated child processes that don't inherit mocked state.
16-
# mp.set_start_method("fork", force=True)
17-
1811

1912
@pytest.fixture
2013
def fxt_active_pipeline_service() -> MagicMock:

backend/tests/unit/services/test_metrics_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_time_window_measurements(self):
9595
collector.record_inference_end(model_id=model_id, start_time=start_time)
9696

9797
# Then add an "old" measurement by mocking datetime
98-
with patch("app.services.metrics_collector.datetime") as mock_datetime:
98+
with patch("app.services.metrics_service.datetime") as mock_datetime:
9999
mock_datetime.now.return_value = datetime.now(UTC) - timedelta(seconds=90)
100100
collector.record_inference_end(model_id, start_time)
101101

@@ -115,7 +115,7 @@ def test_latency_measurement_timestamp(self):
115115
model_id = uuid4()
116116
start_time = collector.record_inference_start()
117117

118-
with patch("app.services.metrics_collector.datetime") as mock_datetime:
118+
with patch("app.services.metrics_service.datetime") as mock_datetime:
119119
mock_datetime.now.return_value = fixed_time
120120
collector.record_inference_end(model_id, start_time)
121121

backend/tests/unit/workers/test_stream_loading.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import multiprocessing as mp
55
import queue
6+
import sys
67
import time
78
from unittest.mock import Mock, patch
89

@@ -93,9 +94,17 @@ def mock_services(mock_config, mock_video_stream):
9394
}
9495

9596

97+
@pytest.mark.skipif(sys.platform == "win32", reason="Multiprocessing 'fork' start method not available on Windows")
9698
class TestFrameAcquisition:
9799
"""Unit tests for the frame acquisition routine"""
98100

101+
@pytest.fixture(scope="session", autouse=True)
102+
def set_multiprocessing_start_method(self):
103+
# Set multiprocessing start method to 'fork' to ensure mocked objects and patches
104+
# from the parent process are inherited by child processes. The default 'spawn'
105+
# method creates isolated child processes that don't inherit mocked state.
106+
mp.set_start_method("fork", force=True)
107+
99108
def test_queue_full(self, frame_queue, mock_stream_data, stop_event, config_changed_condition, mock_services):
100109
"""Test that stream frames are not acquired when queue is full"""
101110

0 commit comments

Comments
 (0)