diff --git a/tests/components/api/test_init.py b/tests/components/api/test_init.py index d56389c7230..d6bfd3de521 100644 --- a/tests/components/api/test_init.py +++ b/tests/components/api/test_init.py @@ -327,35 +327,35 @@ async def test_stream(hass, mock_api_client): """Test the stream.""" listen_count = _listen_count(hass) - resp = await mock_api_client.get(const.URL_API_STREAM) - assert resp.status == HTTPStatus.OK - assert listen_count + 1 == _listen_count(hass) + async with mock_api_client.get(const.URL_API_STREAM) as resp: + assert resp.status == HTTPStatus.OK + assert listen_count + 1 == _listen_count(hass) - hass.bus.async_fire("test_event") + hass.bus.async_fire("test_event") - data = await _stream_next_event(resp.content) + data = await _stream_next_event(resp.content) - assert data["event_type"] == "test_event" + assert data["event_type"] == "test_event" async def test_stream_with_restricted(hass, mock_api_client): """Test the stream with restrictions.""" listen_count = _listen_count(hass) - resp = await mock_api_client.get( + async with mock_api_client.get( f"{const.URL_API_STREAM}?restrict=test_event1,test_event3" - ) - assert resp.status == HTTPStatus.OK - assert listen_count + 1 == _listen_count(hass) + ) as resp: + assert resp.status == HTTPStatus.OK + assert listen_count + 1 == _listen_count(hass) - hass.bus.async_fire("test_event1") - data = await _stream_next_event(resp.content) - assert data["event_type"] == "test_event1" + hass.bus.async_fire("test_event1") + data = await _stream_next_event(resp.content) + assert data["event_type"] == "test_event1" - hass.bus.async_fire("test_event2") - hass.bus.async_fire("test_event3") - data = await _stream_next_event(resp.content) - assert data["event_type"] == "test_event3" + hass.bus.async_fire("test_event2") + hass.bus.async_fire("test_event3") + data = await _stream_next_event(resp.content) + assert data["event_type"] == "test_event3" async def _stream_next_event(stream): diff --git a/tests/components/camera/test_init.py b/tests/components/camera/test_init.py index 3a78740684a..c6d3e1414b2 100644 --- a/tests/components/camera/test_init.py +++ b/tests/components/camera/test_init.py @@ -503,15 +503,17 @@ async def test_camera_proxy_stream(hass, mock_camera, hass_client): client = await hass_client() - response = await client.get("/api/camera_proxy_stream/camera.demo_camera") - assert response.status == HTTPStatus.OK + async with client.get("/api/camera_proxy_stream/camera.demo_camera") as response: + assert response.status == HTTPStatus.OK with patch( "homeassistant.components.demo.camera.DemoCamera.handle_async_mjpeg_stream", return_value=None, ): - response = await client.get("/api/camera_proxy_stream/camera.demo_camera") - assert response.status == HTTPStatus.BAD_GATEWAY + async with await client.get( + "/api/camera_proxy_stream/camera.demo_camera" + ) as response: + assert response.status == HTTPStatus.BAD_GATEWAY async def test_websocket_web_rtc_offer(