Use pytest.mark.parametrize in airthings_ble tests (#119461)

pull/119482/head
epenet 2024-06-12 12:23:24 +02:00 committed by GitHub
parent 7d631c28a6
commit 8323266960
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 14 deletions

View File

@ -4,6 +4,7 @@ from unittest.mock import patch
from airthings_ble import AirthingsDevice, AirthingsDeviceType
from bleak import BleakError
import pytest
from homeassistant.components.airthings_ble.const import DOMAIN
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
@ -71,12 +72,13 @@ async def test_bluetooth_discovery_no_BLEDevice(hass: HomeAssistant) -> None:
assert result["reason"] == "cannot_connect"
@pytest.mark.parametrize(
("exc", "reason"), [(Exception(), "unknown"), (BleakError(), "cannot_connect")]
)
async def test_bluetooth_discovery_airthings_ble_update_failed(
hass: HomeAssistant,
hass: HomeAssistant, exc: Exception, reason: str
) -> None:
"""Test discovery via bluetooth but there's an exception from airthings-ble."""
for loop in [(Exception(), "unknown"), (BleakError(), "cannot_connect")]:
exc, reason = loop
with (
patch_async_ble_device_from_address(WAVE_SERVICE_INFO),
patch_airthings_ble(side_effect=exc),