Skip to content

Commit 7629c9f

Browse files
authored
Fix flaky test_stream_source timeout in generic camera tests (home-assistant#158506)
1 parent 6b8650c commit 7629c9f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/components/generic/test_camera.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import timedelta
55
from http import HTTPStatus
66
from typing import Any
7-
from unittest.mock import patch
7+
from unittest.mock import AsyncMock, Mock, patch
88

99
import aiohttp
1010
from freezegun.api import FrozenDateTimeFactory
@@ -37,7 +37,7 @@
3737
from homeassistant.core import HomeAssistant
3838
from homeassistant.setup import async_setup_component
3939

40-
from tests.common import Mock, MockConfigEntry
40+
from tests.common import MockConfigEntry
4141
from tests.typing import ClientSessionGenerator, WebSocketGenerator
4242

4343

@@ -353,10 +353,16 @@ async def test_stream_source(
353353
stream_source = await async_get_stream_source(hass, "camera.config_test")
354354
assert stream_source == "http://barney:[email protected]/5a"
355355

356+
# Create a mock stream that doesn't actually try to connect
357+
mock_stream = Mock()
358+
mock_stream.add_provider = Mock()
359+
mock_stream.start = AsyncMock()
360+
mock_stream.endpoint_url = Mock(return_value="http://home.assistant/playlist.m3u8")
361+
356362
with patch(
357-
"homeassistant.components.camera.Stream.endpoint_url",
358-
return_value="http://home.assistant/playlist.m3u8",
359-
) as mock_stream_url:
363+
"homeassistant.components.camera.create_stream",
364+
return_value=mock_stream,
365+
):
360366
# Request playlist through WebSocket
361367
client = await hass_ws_client(hass)
362368

@@ -366,7 +372,7 @@ async def test_stream_source(
366372
msg = await client.receive_json()
367373

368374
# Assert WebSocket response
369-
assert mock_stream_url.call_count == 1
375+
assert mock_stream.endpoint_url.call_count == 1
370376
assert msg["id"] == 1
371377
assert msg["type"] == TYPE_RESULT
372378
assert msg["success"]

0 commit comments

Comments
 (0)