Skip to content

Commit 7718544

Browse files
authored
Mock out the zeroconf resolver (hacs#4338)
* Mock out the zeroconf resolver * make it conditional * Fix it
1 parent d277673 commit 7718544

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/conftest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import os
1111
import shutil
1212
from typing import Any
13-
from unittest.mock import MagicMock, patch
13+
from unittest.mock import MagicMock, _patch, patch
1414

15+
from aiohttp import AsyncResolver
1516
from awesomeversion import AwesomeVersion
1617
import freezegun
1718
from homeassistant import loader
@@ -108,6 +109,23 @@ def hass_storage():
108109
yield stored_data
109110

110111

112+
@pytest.fixture(autouse=True, scope="session")
113+
def mock_zeroconf_resolver() -> Generator[_patch]:
114+
"""Mock out the zeroconf resolver."""
115+
if AwesomeVersion(HA_VERSION) < "2025.2.0dev0":
116+
yield None
117+
else:
118+
patcher = patch(
119+
"homeassistant.helpers.aiohttp_client._async_make_resolver",
120+
return_value=AsyncResolver(),
121+
)
122+
patcher.start()
123+
try:
124+
yield patcher
125+
finally:
126+
patcher.stop()
127+
128+
111129
@pytest.fixture
112130
async def hass(time_freezer, event_loop, tmpdir, check_report_issue: None):
113131
"""Fixture to provide a test instance of Home Assistant."""

0 commit comments

Comments
 (0)