Skip to content

Commit 9cd1eaf

Browse files
authored
Run unload_entry, already_configured tests only once (#632)
* run unload test only once all BMSs are identical for unload, so one test is sufficient. Better scales with increasing number of BMSs * run already_configured test only once
1 parent 8f144c4 commit 9cd1eaf

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

tests/test_config_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ async def test_device_not_supported(
196196

197197

198198
@pytest.mark.usefixtures("enable_bluetooth")
199-
async def test_already_configured(bms_fixture: str, hass: HomeAssistant) -> None:
199+
async def test_already_configured(hass: HomeAssistant) -> None:
200200
"""Test that same device cannot be added twice."""
201201

202-
cfg: MockConfigEntry = mock_config(bms_fixture)
202+
cfg: MockConfigEntry = mock_config()
203203
cfg.add_to_hass(hass)
204204

205205
await hass.config_entries.async_setup(cfg.entry_id)
@@ -210,7 +210,7 @@ async def test_already_configured(bms_fixture: str, hass: HomeAssistant) -> None
210210
context={"source": SOURCE_USER},
211211
data={
212212
CONF_ADDRESS: "cc:cc:cc:cc:cc:cc",
213-
"type": "aiobmsble.bms.ogt_bms",
213+
"type": "aiobmsble.bms.dummy_bms",
214214
},
215215
)
216216
assert result.get("type") == FlowResultType.ABORT

tests/test_init.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ async def mock_coord_shutdown(_self) -> None:
6868
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
6969
async def test_unload_entry(
7070
monkeypatch: pytest.MonkeyPatch,
71-
bms_fixture: str,
7271
bool_fixture: bool,
7372
bt_discovery: BluetoothServiceInfoBleak,
7473
hass: HomeAssistant,
@@ -79,12 +78,12 @@ async def test_unload_entry(
7978
# first load entry (see test_async_setup_entry)
8079
inject_bluetooth_service_info_bleak(hass, bt_discovery)
8180

82-
cfg: MockConfigEntry = mock_config(bms=bms_fixture)
81+
cfg: MockConfigEntry = mock_config()
8382
cfg.add_to_hass(hass)
8483

85-
bms_module: Final[str] = f"aiobmsble.bms.{bms_fixture}"
86-
monkeypatch.setattr(f"{bms_module}.BMS.device_info", mock_devinfo_min)
87-
monkeypatch.setattr(f"{bms_module}.BMS.async_update", mock_update_min)
84+
bms_class: Final[str] = "aiobmsble.bms.dummy_bms.BMS"
85+
monkeypatch.setattr(f"{bms_class}.device_info", mock_devinfo_min)
86+
monkeypatch.setattr(f"{bms_class}.async_update", mock_update_min)
8887

8988
async def mock_coord_shutdown(_self) -> None:
9089
trace_fct["shutdown_called"] = True

0 commit comments

Comments
 (0)