mirror of
https://github.com/home-assistant/core.git
synced 2025-09-07 22:01:34 +02:00
Fix bluetooth tests (#150978)
This commit is contained in:
@@ -1846,19 +1846,30 @@ def mock_bleak_scanner_start() -> Generator[MagicMock]:
|
||||
|
||||
# Late imports to avoid loading bleak unless we need it
|
||||
|
||||
from habluetooth import scanner as bluetooth_scanner # noqa: PLC0415
|
||||
from habluetooth import ( # noqa: PLC0415
|
||||
manager as bluetooth_manager,
|
||||
scanner as bluetooth_scanner,
|
||||
)
|
||||
|
||||
# We need to drop the stop method from the object since we patched
|
||||
# out start and this fixture will expire before the stop method is called
|
||||
# when EVENT_HOMEASSISTANT_STOP is fired.
|
||||
# pylint: disable-next=c-extension-no-member
|
||||
bluetooth_scanner.OriginalBleakScanner.stop = AsyncMock() # type: ignore[assignment]
|
||||
|
||||
# Mock BlueZ management controller
|
||||
mock_mgmt_bluetooth_ctl = Mock()
|
||||
mock_mgmt_bluetooth_ctl.setup = AsyncMock(side_effect=OSError("Mocked error"))
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
bluetooth_scanner.OriginalBleakScanner, # pylint: disable=c-extension-no-member
|
||||
"start",
|
||||
) as mock_bleak_scanner_start,
|
||||
patch.object(bluetooth_scanner, "HaScanner"),
|
||||
patch.object(
|
||||
bluetooth_manager, "MGMTBluetoothCtl", return_value=mock_mgmt_bluetooth_ctl
|
||||
),
|
||||
):
|
||||
yield mock_bleak_scanner_start
|
||||
|
||||
|
Reference in New Issue
Block a user