|
18 | 18 | # You should have received a copy of the GNU Lesser Public License |
19 | 19 | # along with this program. If not, see [http://www.gnu.org/licenses/]. |
20 | 20 | import os |
| 21 | +from time import sleep |
21 | 22 |
|
22 | 23 | import pytest |
23 | 24 | from flaky import flaky |
@@ -214,9 +215,12 @@ def test_equality(self, sticker): |
214 | 215 | assert hash(a) != hash(e) |
215 | 216 |
|
216 | 217 |
|
217 | | -@pytest.fixture(scope='class') |
| 218 | +@pytest.fixture(scope='function') |
218 | 219 | 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 |
220 | 224 |
|
221 | 225 |
|
222 | 226 | class TestStickerSet(object): |
@@ -249,18 +253,25 @@ def test_sticker_set_to_dict(self, sticker_set): |
249 | 253 | assert sticker_set_dict['contains_masks'] == sticker_set.contains_masks |
250 | 254 | assert sticker_set_dict['stickers'][0] == sticker_set.stickers[0].to_dict() |
251 | 255 |
|
| 256 | + @flaky(3,1) |
| 257 | + @pytest.mark.timeout(10) |
252 | 258 | def test_bot_methods_1(self, bot, sticker_set): |
253 | 259 | with open('tests/data/telegram_sticker.png', 'rb') as f: |
254 | 260 | file = bot.upload_sticker_file(95205500, f) |
255 | 261 | assert file |
256 | 262 | assert bot.add_sticker_to_set(95205500, sticker_set.name, file.file_id, '😄') |
257 | 263 |
|
258 | | - @pytest.mark.xfail(raises=BadRequest, reason='STICKERSET_NOT_MODIFIED errors on deletion') |
| 264 | + @flaky(3,1) |
| 265 | + @pytest.mark.timeout(10) |
259 | 266 | 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 |
264 | 275 | assert bot.delete_sticker_from_set(file_id) |
265 | 276 |
|
266 | 277 | def test_equality(self): |
|
0 commit comments