MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / test_lifespan_startup_failure

Function test_lifespan_startup_failure

tests/api_utils/test_app.py:185–215  ·  view source on GitHub ↗

Test application startup failure handling.

()

Source from the content-addressed store, hash-verified

183
184@pytest.mark.asyncio
185async def test_lifespan_startup_failure():
186 """Test application startup failure handling."""
187 app_mock = MagicMock()
188
189 mock_logger = MagicMock()
190 state.logger = mock_logger
191
192 with (
193 patch("api_utils.app._setup_logging") as mock_setup_logging,
194 patch("api_utils.app._initialize_globals"),
195 patch("api_utils.app._initialize_proxy_settings"),
196 patch("api_utils.app.load_excluded_models"),
197 patch(
198 "api_utils.app._start_stream_proxy", side_effect=Exception("Startup failed")
199 ),
200 patch(
201 "api_utils.app._shutdown_resources", new_callable=AsyncMock
202 ) as mock_shutdown,
203 patch("api_utils.app.restore_original_streams"),
204 ):
205 mock_setup_logging.return_value = (MagicMock(), MagicMock())
206
207 from api_utils.app import lifespan
208
209 with pytest.raises(RuntimeError, match="Application startup failed"):
210 async with lifespan(app_mock):
211 pass
212
213 # Verify shutdown was called even after failure
214 mock_shutdown.assert_called()
215 mock_logger.critical.assert_called()
216
217
218# --- New Tests for Helper Functions ---

Callers

nothing calls this directly

Calls 1

lifespanFunction · 0.90

Tested by

no test coverage detected