mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Fix zeroconf mocking (#104144)
This commit is contained in:
parent
80813e992d
commit
bf87773d87
@ -1145,13 +1145,19 @@ def mock_zeroconf() -> Generator[None, None, None]:
|
||||
@pytest.fixture
|
||||
def mock_async_zeroconf(mock_zeroconf: None) -> Generator[None, None, None]:
|
||||
"""Mock AsyncZeroconf."""
|
||||
from zeroconf import DNSCache # pylint: disable=import-outside-toplevel
|
||||
from zeroconf import DNSCache, Zeroconf # pylint: disable=import-outside-toplevel
|
||||
from zeroconf.asyncio import ( # pylint: disable=import-outside-toplevel
|
||||
AsyncZeroconf,
|
||||
)
|
||||
|
||||
with patch("homeassistant.components.zeroconf.HaAsyncZeroconf") as mock_aiozc:
|
||||
with patch(
|
||||
"homeassistant.components.zeroconf.HaAsyncZeroconf", spec=AsyncZeroconf
|
||||
) as mock_aiozc:
|
||||
zc = mock_aiozc.return_value
|
||||
zc.async_unregister_service = AsyncMock()
|
||||
zc.async_register_service = AsyncMock()
|
||||
zc.async_update_service = AsyncMock()
|
||||
zc.zeroconf = Mock(spec=Zeroconf)
|
||||
zc.zeroconf.async_wait_for_start = AsyncMock()
|
||||
# DNSCache has strong Cython type checks, and MagicMock does not work
|
||||
# so we must mock the class directly
|
||||
|
Loading…
x
Reference in New Issue
Block a user