From 45a4b936a9742b67b618619a03a9006a341fdf46 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:56:44 +0200 Subject: [PATCH 1/2] Stabilize Flaky Tests --- tests/_files/test_animation.py | 3 ++- tests/test_bot.py | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/_files/test_animation.py b/tests/_files/test_animation.py index a312d3575cd..0f581259db9 100644 --- a/tests/_files/test_animation.py +++ b/tests/_files/test_animation.py @@ -233,7 +233,8 @@ async def test_send_all_args(self, bot, chat_id, animation_file, animation, thum assert message.animation.file_unique_id assert message.animation.file_name == animation.file_name assert message.animation.mime_type == animation.mime_type - assert message.animation.file_size == animation.file_size + # TGs reported file size is not reliable + assert isinstance(message.animation.file_size, int) assert message.animation.thumbnail.width == self.width assert message.animation.thumbnail.height == self.height assert message.has_protected_content diff --git a/tests/test_bot.py b/tests/test_bot.py index 379addbd859..38a5e6f31e6 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -2372,15 +2372,12 @@ async def test_forward_protected_message(self, bot, chat_id): assert all("can't be forwarded" in str(exc) for exc in result) async def test_forward_messages(self, bot, chat_id): - tasks = asyncio.gather( - bot.send_message(chat_id, text="will be forwarded"), - bot.send_message(chat_id, text="will be forwarded"), - ) - - msg1, msg2 = await tasks + # not using gather here to have deteriminically ordered message_ids + msg1 = await bot.send_message(chat_id, text="will be forwarded") + msg2 = await bot.send_message(chat_id, text="will be forwarded") forward_messages = await bot.forward_messages( - chat_id, from_chat_id=chat_id, message_ids=sorted((msg1.message_id, msg2.message_id)) + chat_id, from_chat_id=chat_id, message_ids=(msg1.message_id, msg2.message_id) ) assert isinstance(forward_messages, tuple) @@ -3939,14 +3936,12 @@ async def test_copy_message_with_default(self, default_bot, chat_id, media_messa assert len(message.caption_entities) == 0 async def test_copy_messages(self, bot, chat_id): - tasks = asyncio.gather( - bot.send_message(chat_id, text="will be copied 1"), - bot.send_message(chat_id, text="will be copied 2"), - ) - msg1, msg2 = await tasks + # not using gather here to have deterministically ordered message_ids + msg1 = await bot.send_message(chat_id, text="will be copied 1") + msg2 = await bot.send_message(chat_id, text="will be copied 2") copy_messages = await bot.copy_messages( - chat_id, from_chat_id=chat_id, message_ids=sorted((msg1.message_id, msg2.message_id)) + chat_id, from_chat_id=chat_id, message_ids=(msg1.message_id, msg2.message_id) ) assert isinstance(copy_messages, tuple) @@ -4079,6 +4074,10 @@ async def test_get_chat_arbitrary_callback_data(self, channel_id, cdc_bot): assert data == "callback_data" cfi = await bot.get_chat(channel_id) + + if not cfi.pinned_message: + pytest.xfail("Pinning messages is not always reliable on TG") + assert cfi.pinned_message == message assert cfi.pinned_message.reply_markup == reply_markup assert await message.unpin() # (not placed in finally block since msg can be unbound) From 8b3da45384b27dedb7c95b7f118c46fb79911ce4 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:07:39 +0200 Subject: [PATCH 2/2] Further improve `test_get_chat_arbitrary_callback_data` --- tests/test_bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_bot.py b/tests/test_bot.py index 38a5e6f31e6..426b5aa6637 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -4054,7 +4054,7 @@ async def test_replace_callback_data_copy_message(self, cdc_bot, chat_id): bot.callback_data_cache.clear_callback_data() bot.callback_data_cache.clear_callback_queries() - async def test_get_chat_arbitrary_callback_data(self, channel_id, cdc_bot): + async def test_get_chat_arbitrary_callback_data(self, chat_id, cdc_bot): bot = cdc_bot try: @@ -4063,7 +4063,7 @@ async def test_get_chat_arbitrary_callback_data(self, channel_id, cdc_bot): ) message = await bot.send_message( - channel_id, text="get_chat_arbitrary_callback_data", reply_markup=reply_markup + chat_id, text="get_chat_arbitrary_callback_data", reply_markup=reply_markup ) await message.pin() @@ -4073,7 +4073,7 @@ async def test_get_chat_arbitrary_callback_data(self, channel_id, cdc_bot): ) assert data == "callback_data" - cfi = await bot.get_chat(channel_id) + cfi = await bot.get_chat(chat_id) if not cfi.pinned_message: pytest.xfail("Pinning messages is not always reliable on TG") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy