Fix homekit_controller tests to avoid global aid generation (#119852)

This commit is contained in:
J. Nick Koston 2024-07-17 19:10:02 -05:00 committed by GitHub
parent 454ca0ce95
commit e2276458ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 792 additions and 344 deletions

View file

@ -1,6 +1,6 @@
"""HomeKit controller session fixtures."""
from collections.abc import Generator
from collections.abc import Callable, Generator
import datetime
from unittest.mock import MagicMock, patch
@ -44,3 +44,16 @@ def hk_mock_async_zeroconf(mock_async_zeroconf: MagicMock) -> None:
@pytest.fixture(autouse=True)
def auto_mock_bluetooth(mock_bluetooth: None) -> None:
"""Auto mock bluetooth."""
@pytest.fixture
def get_next_aid() -> Generator[Callable[[], int]]:
"""Generate a function that returns increasing accessory ids."""
id_counter = 0
def _get_id():
nonlocal id_counter
id_counter += 1
return id_counter
return _get_id