Skip to content

Commit e13cd58

Browse files
authored
Fix sticker tests (python-telegram-bot#807)
* Fix sticker tests Added flaky, timeout and xfails to the stickerset bot method tests. * Make sure the first stickersettest worked before modifying in test 2 * some mor changes to make the deletion more stable
1 parent 1f5311b commit e13cd58

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tests/test_sticker.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# You should have received a copy of the GNU Lesser Public License
1919
# along with this program. If not, see [http://www.gnu.org/licenses/].
2020
import os
21+
from time import sleep
2122

2223
import pytest
2324
from flaky import flaky
@@ -214,9 +215,12 @@ def test_equality(self, sticker):
214215
assert hash(a) != hash(e)
215216

216217

217-
@pytest.fixture(scope='class')
218+
@pytest.fixture(scope='function')
218219
def sticker_set(bot):
219-
return bot.get_sticker_set('test_by_{0}'.format(bot.username))
220+
ss = bot.get_sticker_set('test_by_{0}'.format(bot.username))
221+
if len(ss.stickers) > 100:
222+
raise Exception('stickerset is growing too large.')
223+
return ss
220224

221225

222226
class TestStickerSet(object):
@@ -249,18 +253,25 @@ def test_sticker_set_to_dict(self, sticker_set):
249253
assert sticker_set_dict['contains_masks'] == sticker_set.contains_masks
250254
assert sticker_set_dict['stickers'][0] == sticker_set.stickers[0].to_dict()
251255

256+
@flaky(3,1)
257+
@pytest.mark.timeout(10)
252258
def test_bot_methods_1(self, bot, sticker_set):
253259
with open('tests/data/telegram_sticker.png', 'rb') as f:
254260
file = bot.upload_sticker_file(95205500, f)
255261
assert file
256262
assert bot.add_sticker_to_set(95205500, sticker_set.name, file.file_id, '😄')
257263

258-
@pytest.mark.xfail(raises=BadRequest, reason='STICKERSET_NOT_MODIFIED errors on deletion')
264+
@flaky(3,1)
265+
@pytest.mark.timeout(10)
259266
def test_bot_methods_2(self, bot, sticker_set):
260-
updated_sticker_set = bot.get_sticker_set(sticker_set.name)
261-
assert len(updated_sticker_set.stickers) > 1 # Otherwise test_bot_methods_1 failed
262-
file_id = updated_sticker_set.stickers[-1].file_id
263-
assert bot.set_sticker_position_in_set(file_id, len(updated_sticker_set.stickers) - 1)
267+
file_id = sticker_set.stickers[0].file_id
268+
assert bot.set_sticker_position_in_set(file_id, 1)
269+
270+
@flaky(10, 1)
271+
@pytest.mark.timeout(10)
272+
def test_bot_methods_3(self, bot, sticker_set):
273+
sleep(1)
274+
file_id = sticker_set.stickers[-1].file_id
264275
assert bot.delete_sticker_from_set(file_id)
265276

266277
def test_equality(self):

0 commit comments

Comments
 (0)