Small test fixes to make them more stable on travis CI

This commit is contained in:
Jasmin Bom 2018-09-07 16:05:45 +02:00
parent 19591c955a
commit b2fb4264a3
6 changed files with 18 additions and 1 deletions

View file

@ -18,6 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import pytest import pytest
from flaky import flaky
from telegram import ForceReply from telegram import ForceReply
@ -31,6 +32,8 @@ class TestForceReply(object):
force_reply = True force_reply = True
selective = True selective = True
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_message_with_force_reply(self, bot, chat_id, force_reply): def test_send_message_with_force_reply(self, bot, chat_id, force_reply):
message = bot.send_message(chat_id, 'text', reply_markup=force_reply) message = bot.send_message(chat_id, 'text', reply_markup=force_reply)

View file

@ -18,6 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import pytest import pytest
from flaky import flaky
from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram import InlineKeyboardButton, InlineKeyboardMarkup
@ -33,6 +34,8 @@ class TestInlineKeyboardMarkup(object):
InlineKeyboardButton(text='button2', callback_data='data2') InlineKeyboardButton(text='button2', callback_data='data2')
]] ]]
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_message_with_inline_keyboard_markup(self, bot, chat_id, inline_keyboard_markup): def test_send_message_with_inline_keyboard_markup(self, bot, chat_id, inline_keyboard_markup):
message = bot.send_message( message = bot.send_message(
chat_id, chat_id,

View file

@ -316,6 +316,8 @@ class TestSendMediaGroup(object):
assert all([isinstance(mes, Message) for mes in messages]) assert all([isinstance(mes, Message) for mes in messages])
assert all([mes.media_group_id == messages[0].media_group_id for mes in messages]) assert all([mes.media_group_id == messages[0].media_group_id for mes in messages])
@flaky(3, 1) # noqa: F811
@pytest.mark.timeout(10) # noqa: F811
def test_send_media_group_new_files(self, bot, chat_id, video_file, photo_file, # noqa: F811 def test_send_media_group_new_files(self, bot, chat_id, video_file, photo_file, # noqa: F811
animation_file): # noqa: F811 animation_file): # noqa: F811
messages = bot.send_media_group(chat_id, [ messages = bot.send_media_group(chat_id, [

View file

@ -16,6 +16,8 @@
# #
# You should have received a copy of the GNU Lesser Public License # You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import pytest
from flaky import flaky
from telegram import ParseMode from telegram import ParseMode
@ -25,12 +27,16 @@ class TestParseMode(object):
html_text = '<b>bold</b> <i>italic</i> <a href="http://google.com">link</a>.' html_text = '<b>bold</b> <i>italic</i> <a href="http://google.com">link</a>.'
formatted_text_formatted = u'bold italic link.' formatted_text_formatted = u'bold italic link.'
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_message_with_parse_mode_markdown(self, bot, chat_id): def test_send_message_with_parse_mode_markdown(self, bot, chat_id):
message = bot.send_message(chat_id=chat_id, text=self.markdown_text, message = bot.send_message(chat_id=chat_id, text=self.markdown_text,
parse_mode=ParseMode.MARKDOWN) parse_mode=ParseMode.MARKDOWN)
assert message.text == self.formatted_text_formatted assert message.text == self.formatted_text_formatted
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_message_with_parse_mode_html(self, bot, chat_id): def test_send_message_with_parse_mode_html(self, bot, chat_id):
message = bot.send_message(chat_id=chat_id, text=self.html_text, message = bot.send_message(chat_id=chat_id, text=self.html_text,
parse_mode=ParseMode.HTML) parse_mode=ParseMode.HTML)

View file

@ -18,6 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import pytest import pytest
from flaky import flaky
from telegram import ReplyKeyboardRemove from telegram import ReplyKeyboardRemove
@ -31,6 +32,8 @@ class TestReplyKeyboardRemove(object):
remove_keyboard = True remove_keyboard = True
selective = True selective = True
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_message_with_reply_keyboard_remove(self, bot, chat_id, reply_keyboard_remove): def test_send_message_with_reply_keyboard_remove(self, bot, chat_id, reply_keyboard_remove):
message = bot.send_message(chat_id, 'Text', reply_markup=reply_keyboard_remove) message = bot.send_message(chat_id, 'Text', reply_markup=reply_keyboard_remove)

View file

@ -103,7 +103,7 @@ class TestUpdater(object):
monkeypatch.setattr('telegram.Bot.set_webhook', lambda *args, **kwargs: True) monkeypatch.setattr('telegram.Bot.set_webhook', lambda *args, **kwargs: True)
updater.dispatcher.add_error_handler(self.error_handler) updater.dispatcher.add_error_handler(self.error_handler)
updater.start_polling(0.01) updater.start_polling(0.01)
assert self.err_handler_called.wait(0.5) is not True assert self.err_handler_called.wait(1) is not True
# NOTE: This test might hit a race condition and fail (though the 0.5 seconds delay above # NOTE: This test might hit a race condition and fail (though the 0.5 seconds delay above
# should work around it). # should work around it).