From 210ec28f0af6fe7f550ca519552f6eb2959df1fd Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 21 Aug 2025 09:38:42 +0200 Subject: [PATCH] Fix bluetooth tests (#150978) --- tests/conftest.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index acb50b0029c..130ce74dd5b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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