From 2a40bd7b71408ffd9aa6b3acfd40d35edca4d14d Mon Sep 17 00:00:00 2001 From: Stefan Allius <122395479+s-allius@users.noreply.github.com> Date: Mon, 26 May 2025 23:42:13 +0200 Subject: [PATCH] S allius/issue427 (#435) * mock the aiomqtt library and increse coverage * test inv response for a mb scan request * improve test coverage * improve test case --- app/tests/test_mqtt.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/tests/test_mqtt.py b/app/tests/test_mqtt.py index 0906bd4..2266132 100755 --- a/app/tests/test_mqtt.py +++ b/app/tests/test_mqtt.py @@ -182,13 +182,17 @@ async def test_ha_reconnect(config_mqtt_conn): await m.close() @pytest.mark.asyncio -async def test_mqtt_no_config(config_no_conn): +async def test_mqtt_no_config(config_no_conn, monkeypatch): _ = config_no_conn assert asyncio.get_running_loop() on_connect = asyncio.Event() async def cb(): on_connect.set() + async def my_publish(*args): + return + + monkeypatch.setattr(aiomqtt.Client, "publish", my_publish) try: m = Mqtt(cb) @@ -197,9 +201,9 @@ async def test_mqtt_no_config(config_no_conn): assert not on_connect.is_set() try: await m.publish('homeassistant/status', 'online') - assert False + assert m.published == 1 except Exception: - pass + assert False except TimeoutError: assert False finally: