From 9a1cbb1235113796bd94ce3747227c71a9cf794c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Sun, 18 Feb 2024 01:33:48 -0400 Subject: [PATCH] test: Add xfail test for reusing messages generator after disconnection; #268 --- tests/test_client.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 58c4443..9136988 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -367,17 +367,20 @@ async def test_aexit_client_is_already_disconnected_failure() -> None: await client.__aexit__(None, None, None) +@pytest.mark.xfail @pytest.mark.network async def test_messages_generator_is_reusable() -> None: - """Test that the messages generator is reusable and returns no duplicates.""" + """Test that the messages generator is reusable after dis- and reconnection.""" topic = TOPIC_PREFIX + "test_messages_generator_is_reusable" - async with Client(HOSTNAME) as client: + client = Client(HOSTNAME) + async with client: + client._disconnected.set_result(None) + with pytest.raises(MqttError): + # TODO(felix): Switch to anext function from Python 3.10 + await client.messages.__anext__() + async with client: await client.subscribe(topic) await client.publish(topic, "foo") - await client.publish(topic, "bar") - async for message in client.messages: - assert message.payload == b"foo" - break - async for message in client.messages: - assert message.payload == b"bar" - break + # TODO(felix): Switch to anext function from Python 3.10 + message = await client.messages.__anext__() + assert message.payload == b"foo"