@@ -28,6 +28,18 @@ def test_config_to_dict(self):
2828class TestLayoutDeviceUnit :
2929 """Unit tests for layout device selection and config plumbing (mocked)."""
3030
31+ @staticmethod
32+ def _require_layout_runtime ():
33+ """Require optional self-hosted layout deps, otherwise skip tests."""
34+ torch = pytest .importorskip (
35+ "torch" , reason = "layout device unit tests require optional selfhosted deps"
36+ )
37+ pytest .importorskip (
38+ "transformers" ,
39+ reason = "layout device unit tests require optional selfhosted deps" ,
40+ )
41+ return torch
42+
3143 def test_layout_config_device_default_is_none (self ):
3244 """LayoutConfig.device defaults to None (auto-select)."""
3345 from glmocr .config import LayoutConfig
@@ -89,6 +101,7 @@ def test_from_env_layout_device_kwarg(self, monkeypatch):
89101
90102 def _mock_detector (self , device_val ):
91103 """Create a PPDocLayoutDetector with mocked model, ready for start()."""
104+ self ._require_layout_runtime ()
92105 from glmocr .config import LayoutConfig
93106 from glmocr .layout .layout_detector import PPDocLayoutDetector
94107
@@ -143,7 +156,7 @@ def test_detector_device_selection_explicit_cuda(self):
143156
144157 def test_detector_device_selection_auto_fallback_cpu (self ):
145158 """When config.device=None and CUDA unavailable, auto-selects CPU."""
146- import torch
159+ torch = self . _require_layout_runtime ()
147160
148161 det , mock_model , mock_proc = self ._mock_detector (None )
149162
@@ -164,7 +177,7 @@ def test_detector_device_selection_auto_fallback_cpu(self):
164177
165178 def test_detector_device_selection_auto_cuda (self ):
166179 """When config.device=None and CUDA available, auto-selects cuda:{cuda_visible_devices}."""
167- import torch
180+ torch = self . _require_layout_runtime ()
168181 from glmocr .config import LayoutConfig
169182 from glmocr .layout .layout_detector import PPDocLayoutDetector
170183
0 commit comments