Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Stabilize Some Flaky Tests #4500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/_files/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 15 additions & 16 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -4059,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:
Expand All @@ -4068,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()

Expand All @@ -4078,7 +4073,11 @@ 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")

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)
Expand Down
Loading