Test application startup failure handling.
()
| 183 | |
| 184 | @pytest.mark.asyncio |
| 185 | async 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 --- |
nothing calls this directly
no test coverage detected