10000 Stabilize `test_delete_sticker_set` (#3685) · Devors/python-telegram-bot@83ab12c · GitHub
[go: up one dir, main page]

Skip to content

Commit 83ab12c

Browse files
Stabilize test_delete_sticker_set (python-telegram-bot#3685)
Co-authored-by: poolitzer <github@poolitzer.eu>
1 parent 3f444da commit 83ab12c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tests/_files/test_sticker.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
import asyncio
2020
import os
21+
import random
22+
import string
2123
from pathlib import Path
2224

2325
import pytest
@@ -1016,17 +1018,22 @@ async def test_create_sticker_set(
10161018
assert v
10171019

10181020
async def test_delete_sticker_set(self, bot, chat_id, sticker_file):
1019-
try:
1020-
# try creating a new sticker set - just in case the last deletion test failed
1021-
assert await bot.create_new_sticker_set(
1022-
chat_id,
1023-
name=f"temp_set_by_{bot.username}",
1024-
title="Stickerset delete Test",
1025-
stickers=[InputSticker(sticker_file, emoji_list=["😄"])],
1026-
sticker_format=StickerFormat.STATIC,
1027-
)
1028-
finally:
1029-
assert await bot.delete_sticker_set(f"temp_set_by_{bot.username}")
1021+
# there is currently an issue in the API where this function claims it successfully
1022+
# creates an already deleted sticker set while it does not. This happens when calling it
1023+
# too soon after deleting the set. This then leads to delete_sticker_set failing since the
1024+
# pack does not exist. Making the name random prevents this issue.
1025+
name = f"{''.join(random.choices(string.ascii_lowercase, k=5))}_temp_set_by_{bot.username}"
1026+
assert await bot.create_new_sticker_set(
1027+
chat_id,
1028+
name=name,
1029+
title="Stickerset delete Test",
1030+
stickers=[InputSticker(sticker_file, emoji_list=["😄"])],
1031+
sticker_format=StickerFormat.STATIC,
1032+
)
1033+
# this prevents a second issue when calling delete too soon after creating the set leads
1034+
# to it failing as well
1035+
await asyncio.sleep(1)
1036+
assert await bot.delete_sticker_set(name)
10301037

10311038
async def test_set_custom_emoji_sticker_set_thumbnail(
10321039
self, bot, chat_id, animated_sticker_file

0 commit comments

Comments
 (0)
0