mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix flaky ESPHome test fixture (#94465)
This commit is contained in:
parent
d84b8a0288
commit
86f2aa84e5
@ -1,9 +1,10 @@
|
|||||||
"""esphome session fixtures."""
|
"""esphome session fixtures."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from asyncio import Event
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
from aioesphomeapi import APIClient, APIVersion, DeviceInfo
|
from aioesphomeapi import APIClient, APIVersion, DeviceInfo, ReconnectLogic
|
||||||
import pytest
|
import pytest
|
||||||
from zeroconf import Zeroconf
|
from zeroconf import Zeroconf
|
||||||
|
|
||||||
@ -160,10 +161,18 @@ async def mock_voice_assistant_entry(
|
|||||||
mock_client.device_info = AsyncMock(return_value=device_info)
|
mock_client.device_info = AsyncMock(return_value=device_info)
|
||||||
mock_client.subscribe_voice_assistant = AsyncMock(return_value=Mock())
|
mock_client.subscribe_voice_assistant = AsyncMock(return_value=Mock())
|
||||||
|
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
try_connect_done = Event()
|
||||||
await hass.async_block_till_done()
|
real_try_connect = ReconnectLogic._try_connect
|
||||||
await hass.async_block_till_done()
|
|
||||||
await hass.async_block_till_done()
|
async def mock_try_connect(self):
|
||||||
|
"""Set an event when ReconnectLogic._try_connect has been awaited."""
|
||||||
|
result = await real_try_connect(self)
|
||||||
|
try_connect_done.set()
|
||||||
|
return result
|
||||||
|
|
||||||
|
with patch.object(ReconnectLogic, "_try_connect", mock_try_connect):
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await try_connect_done.wait()
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user