Skip to content

Commit

Permalink
Mock out the zeroconf resolver (#4338)
Browse files Browse the repository at this point in the history
* Mock out the zeroconf resolver

* make it conditional

* Fix it
  • Loading branch information
ludeeus authored Jan 7, 2025
1 parent d277673 commit 7718544
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import os
import shutil
from typing import Any
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock, _patch, patch

from aiohttp import AsyncResolver
from awesomeversion import AwesomeVersion
import freezegun
from homeassistant import loader
Expand Down Expand Up @@ -108,6 +109,23 @@ def hass_storage():
yield stored_data


@pytest.fixture(autouse=True, scope="session")
def mock_zeroconf_resolver() -> Generator[_patch]:
"""Mock out the zeroconf resolver."""
if AwesomeVersion(HA_VERSION) < "2025.2.0dev0":
yield None
else:
patcher = patch(
"homeassistant.helpers.aiohttp_client._async_make_resolver",
return_value=AsyncResolver(),
)
patcher.start()
try:
yield patcher
finally:
patcher.stop()


@pytest.fixture
async def hass(time_freezer, event_loop, tmpdir, check_report_issue: None):
"""Fixture to provide a test instance of Home Assistant."""
Expand Down

0 comments on commit 7718544

Please sign in to comment.