X Tutup
Skip to content

Commit e0cf0ab

Browse files
committed
flaky tests: try up to 3 times, need to succeed once
1 parent ec13a36 commit e0cf0ab

File tree

8 files changed

+59
-60
lines changed

8 files changed

+59
-60
lines changed

tests/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import signal
2525
import traceback
2626

27-
from nose.tools import make_decorator, TimeExpired
27+
from nose.tools import make_decorator
2828

2929
sys.path.append('.')
3030

@@ -64,8 +64,7 @@ def is_dict(dictionary):
6464
class TestTimedOut(AssertionError):
6565

6666
def __init__(self, time_limit, frame):
67-
super(TestTimedOut, self).__init__('time_limit={0}\n{1}'.format(
68-
time_limit, ''.join(traceback.format_stack(frame))))
67+
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
6968
self.time_limit = time_limit
7069
self.frame = frame
7170

tests/test_audio.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def setUp(self):
5252
'file_size': self.file_size
5353
}
5454

55-
@flaky
55+
@flaky(3, 1)
5656
@timeout(10)
5757
def test_send_audio_required_args_only(self):
5858
"""Test telegram.Bot sendAudio method"""
@@ -71,7 +71,7 @@ def test_send_audio_required_args_only(self):
7171
self.assertEqual(audio.mime_type, self.mime_type)
7272
self.assertEqual(audio.file_size, self.file_size)
7373

74-
@flaky
74+
@flaky(3, 1)
7575
@timeout(10)
7676
def test_send_audio_all_args(self):
7777
"""Test telegram.Bot sendAudio method"""
@@ -95,7 +95,7 @@ def test_send_audio_all_args(self):
9595
self.assertEqual(audio.mime_type, self.mime_type)
9696
self.assertEqual(audio.file_size, self.file_size)
9797

98-
@flaky
98+
@flaky(3, 1)
9999
@timeout(10)
100100
def test_send_audio_mp3_file(self):
101101
"""Test telegram.Bot sendAudio method"""
@@ -117,7 +117,7 @@ def test_send_audio_mp3_file(self):
117117
self.assertEqual(audio.mime_type, self.mime_type)
118118
self.assertEqual(audio.file_size, self.file_size)
119119

120-
@flaky
120+
@flaky(3, 1)
121121
@timeout(10)
122122
def test_send_audio_mp3_file_custom_filename(self):
123123
"""Test telegram.Bot sendAudio method"""
@@ -140,7 +140,7 @@ def test_send_audio_mp3_file_custom_filename(self):
140140
self.assertEqual(audio.mime_type, self.mime_type)
141141
self.assertEqual(audio.file_size, self.file_size)
142142

143-
@flaky
143+
@flaky(3, 1)
144144
@timeout(10)
145145
def test_send_audio_mp3_url_file(self):
146146
"""Test telegram.Bot sendAudio method"""
@@ -162,7 +162,7 @@ def test_send_audio_mp3_url_file(self):
162162
self.assertEqual(audio.mime_type, self.mime_type)
163163
self.assertEqual(audio.file_size, self.file_size)
164164

165-
@flaky
165+
@flaky(3, 1)
166166
@timeout(10)
167167
def test_send_audio_resend(self):
168168
"""Test telegram.Bot sendAudio method"""
@@ -217,7 +217,7 @@ def test_audio_to_dict(self):
217217
self.assertEqual(audio['mime_type'], self.mime_type)
218218
self.assertEqual(audio['file_size'], self.file_size)
219219

220-
@flaky
220+
@flaky(3, 1)
221221
@timeout(10)
222222
def test_error_send_audio_empty_file(self):
223223
print('Testing bot.sendAudio - Null file')
@@ -231,7 +231,7 @@ def test_error_send_audio_empty_file(self):
231231
lambda: self._bot.sendAudio(chat_id=self._chat_id,
232232
**json_dict))
233233

234-
@flaky
234+
@flaky(3, 1)
235235
@timeout(10)
236236
def test_error_send_audio_empty_file_id(self):
237237
print('Testing bot.sendAudio - Empty file_id')
@@ -245,7 +245,7 @@ def test_error_send_audio_empty_file_id(self):
245245
lambda: self._bot.sendAudio(chat_id=self._chat_id,
246246
**json_dict))
247247

248-
@flaky
248+
@flaky(3, 1)
249249
@timeout(10)
250250
def test_error_audio_without_required_args(self):
251251
print('Testing bot.sendAudio - Without required arguments')

tests/test_bot.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
class BotTest(BaseTest, unittest.TestCase):
4040
"""This object represents Tests for Telegram Bot."""
4141

42-
@flaky
42+
@flaky(3, 1)
4343
@timeout(10)
4444
def testGetMe(self):
4545
'''Test the telegram.Bot getMe method'''
@@ -53,7 +53,7 @@ def testGetMe(self):
5353
self.assertEqual(bot.username, 'PythonTelegramBot')
5454
self.assertEqual(bot.name, '@PythonTelegramBot')
5555

56-
@flaky
56+
@flaky(3, 1)
5757
@timeout(10)
5858
def testSendMessage(self):
5959
'''Test the telegram.Bot sendMessage method'''
@@ -65,7 +65,7 @@ def testSendMessage(self):
6565
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
6666
self.assertTrue(isinstance(message.date, datetime))
6767

68-
@flaky
68+
@flaky(3, 1)
6969
@timeout(10)
7070
def testGetUpdates(self):
7171
'''Test the telegram.Bot getUpdates method'''
@@ -76,7 +76,7 @@ def testGetUpdates(self):
7676
self.assertTrue(self.is_json(updates[0].to_json()))
7777
self.assertTrue(isinstance(updates[0], telegram.Update))
7878

79-
@flaky
79+
@flaky(3, 1)
8080
@timeout(10)
8181
def testForwardMessage(self):
8282
'''Test the telegram.Bot forwardMessage method'''
@@ -90,7 +90,7 @@ def testForwardMessage(self):
9090
self.assertEqual(message.forward_from.username, 'leandrotoledo')
9191
self.assertTrue(isinstance(message.forward_date, datetime))
9292

93-
@flaky
93+
@flaky(3, 1)
9494
@timeout(10)
9595
def testSendPhoto(self):
9696
'''Test the telegram.Bot sendPhoto method'''
@@ -103,7 +103,7 @@ def testSendPhoto(self):
103103
self.assertEqual(message.photo[0].file_size, 1451)
104104
self.assertEqual(message.caption, 'testSendPhoto')
105105

106-
@flaky
106+
@flaky(3, 1)
107107
@timeout(10)
108108
def testResendPhoto(self):
109109
'''Test the telegram.Bot sendPhoto method'''
@@ -114,7 +114,7 @@ def testResendPhoto(self):
114114
self.assertTrue(self.is_json(message.to_json()))
115115
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
116116

117-
@flaky
117+
@flaky(3, 1)
118118
@timeout(10)
119119
def testSendJPGURLPhoto(self):
120120
'''Test the telegram.Bot sendPhoto method'''
@@ -125,7 +125,7 @@ def testSendJPGURLPhoto(self):
125125
self.assertTrue(self.is_json(message.to_json()))
126126
self.assertEqual(message.photo[0].file_size, 822)
127127

128-
@flaky
128+
@flaky(3, 1)
129129
@timeout(10)
130130
def testSendPNGURLPhoto(self):
131131
'''Test the telegram.Bot sendPhoto method'''
@@ -136,7 +136,7 @@ def testSendPNGURLPhoto(self):
136136
self.assertTrue(self.is_json(message.to_json()))
137137
self.assertEqual(message.photo[0].file_size, 684)
138138

139-
@flaky
139+
@flaky(3, 1)
140140
@timeout(10)
141141
def testSendGIFURLPhoto(self):
142142
'''Test the telegram.Bot sendPhoto method'''
@@ -147,7 +147,7 @@ def testSendGIFURLPhoto(self):
147147
self.assertTrue(self.is_json(message.to_json()))
148148
self.assertEqual(message.photo[0].file_size, 684)
149149

150-
@flaky
150+
@flaky(3, 1)
151151
@timeout(10)
152152
def testSendChatAction(self):
153153
'''Test the telegram.Bot sendChatAction method'''
@@ -156,7 +156,7 @@ def testSendChatAction(self):
156156
self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
157157
chat_id=self._chat_id)
158158

159-
@flaky
159+
@flaky(3, 1)
160160
@timeout(10)
161161
def testGetUserProfilePhotos(self):
162162
'''Test the telegram.Bot getUserProfilePhotos method'''

tests/test_document.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def setUp(self):
5353
'file_size': self.file_size
5454
}
5555

56-
@flaky
56+
@flaky(3, 1)
5757
@timeout(10)
5858
def test_send_document_png_file(self):
5959
"""Test telegram.Bot sendDocument method"""
@@ -71,7 +71,7 @@ def test_send_document_png_file(self):
7171
self.assertEqual(document.mime_type, self.mime_type)
7272
self.assertEqual(document.file_size, self.file_size)
7373

74-
@flaky
74+
@flaky(3, 1)
7575
@timeout(10)
7676
def test_send_document_png_file_with_custom_file_name(self):
7777
"""Test telegram.Bot sendDocument method"""
@@ -90,7 +90,7 @@ def test_send_document_png_file_with_custom_file_name(self):
9090
self.assertEqual(document.mime_type, self.mime_type)
9191
self.assertEqual(document.file_size, self.file_size)
9292

93-
@flaky
93+
@flaky(3, 1)
9494
@timeout(10)
9595
def test_send_document_url_gif_file(self):
9696
"""Test telegram.Bot sendDocument method"""
@@ -108,7 +108,7 @@ def test_send_document_url_gif_file(self):
108108
self.assertEqual(document.mime_type, 'image/gif')
109109
self.assertEqual(document.file_size, 3878)
110110

111-
@flaky
111+
@flaky(3, 1)
112112
@timeout(10)
113113
def test_send_document_resend(self):
114114
"""Test telegram.Bot sendDocument method"""
@@ -157,7 +157,7 @@ def test_document_to_dict(self):
157157
self.assertEqual(document['mime_type'], self.mime_type)
158158
self.assertEqual(document['file_size'], self.file_size)
159159

160-
@flaky
160+
@flaky(3, 1)
161161
@timeout(10)
162162
def test_error_send_document_empty_file(self):
163163
print('Testing bot.sendDocument - Null file')
@@ -171,7 +171,7 @@ def test_error_send_document_empty_file(self):
171171
lambda: self._bot.sendDocument(chat_id=self._chat_id,
172172
**json_dict))
173173

174-
@flaky
174+
@flaky(3, 1)
175175
@timeout(10)
176176
def test_error_send_document_empty_file_id(self):
177177
print('Testing bot.sendDocument - Empty file_id')
@@ -185,7 +185,7 @@ def test_error_send_document_empty_file_id(self):
185185
lambda: self._bot.sendDocument(chat_id=self._chat_id,
186186
**json_dict))
187187

188-
@flaky
188+
@flaky(3, 1)
189189
@timeout(10)
190190
def test_error_document_without_required_args(self):
191191
print('Testing bot.sendDocument - Without required arguments')

tests/test_photo.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def setUp(self):
5555
'file_size': self.file_size
5656
}
5757

58-
@flaky
58+
@flaky(3, 1)
5959
@timeout(10)
6060
def test_sendphotoo_all_args(self):
6161
"""Test telegram.Bot sendAudio method"""
@@ -83,7 +83,7 @@ def test_sendphotoo_all_args(self):
8383

8484
self.assertEqual(message.caption, self.caption)
8585

86-
@flaky
86+
@flaky(3, 1)
8787
@timeout(10)
8888
def test_send_photo_jpg_file(self):
8989
"""Test telegram.Bot sendPhoto method"""
@@ -108,7 +108,7 @@ def test_send_photo_jpg_file(self):
108108
self.assertEqual(photo.height, self.height)
109109
self.assertEqual(photo.file_size, self.file_size)
110110

111-
@flaky
111+
@flaky(3, 1)
112112
@timeout(10)
113113
def test_send_photo_url_jpg_file(self):
114114
"""Test telegram.Bot sendPhoto method"""
@@ -133,7 +133,7 @@ def test_send_photo_url_jpg_file(self):
133133
self.assertEqual(photo.height, self.height)
134134
self.assertEqual(photo.file_size, self.file_size)
135135

136-
@flaky
136+
@flaky(3, 1)
137137
@timeout(10)
138138
def test_send_photo_resend(self):
139139
"""Test telegram.Bot sendPhoto method"""
@@ -187,7 +187,7 @@ def test_photo_to_dict(self):
187187
self.assertEqual(photo['height'], self.height)
188188
self.assertEqual(photo['file_size'], self.file_size)
189189

190-
@flaky
190+
@flaky(3, 1)
191191
@timeout(10)
192192
def test_error_send_photo_empty_file(self):
193193
print('Testing bot.sendPhoto - Null file')
@@ -201,7 +201,7 @@ def test_error_send_photo_empty_file(self):
201201
lambda: self._bot.sendPhoto(chat_id=self._chat_id,
202202
**json_dict))
203203

204-
@flaky
204+
@flaky(3, 1)
205205
@timeout(10)
206206
def test_error_send_photo_empty_file_id(self):
207207
print('Testing bot.sendPhoto - Empty file_id')
@@ -215,7 +215,7 @@ def test_error_send_photo_empty_file_id(self):
215215
lambda: self._bot.sendPhoto(chat_id=self._chat_id,
216216
**json_dict))
217217

218-
@flaky
218+
@flaky(3, 1)
219219
@timeout(10)
220220
def test_error_photo_without_required_args(self):
221221
print('Testing bot.sendPhoto - Without required arguments')

tests/test_sticker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def setUp(self):
5151
'file_size': self.file_size
5252
}
5353

54-
@flaky
54+
@flaky(3, 1)
5555
@timeout(10)
5656
def test_send_sticker_file(self):
5757
pass
5858

59-
@flaky
59+
@flaky(3, 1)
6060
@timeout(10)
6161
def test_send_sticker_resend(self):
6262
"""Test telegram.Bot sendSticker method"""
@@ -105,7 +105,7 @@ def test_sticker_to_dict(self):
105105
self.assertTrue(isinstance(sticker['thumb'], telegram.PhotoSize))
106106
self.assertEqual(sticker['file_size'], self.file_size)
107107

108-
@flaky
108+
@flaky(3, 1)
109109
@timeout(10)
110110
def test_error_send_sticker_empty_file(self):
111111
print('Testing bot.sendSticker - Null file')
@@ -119,7 +119,7 @@ def test_error_send_sticker_empty_file(self):
119119
lambda: self._bot.sendSticker(chat_id=self._chat_id,
120120
**json_dict))
121121

122-
@flaky
122+
@flaky(3, 1)
123123
@timeout(10)
124124
def test_error_send_sticker_empty_file_id(self):
125125
print('Testing bot.sendSticker - Empty file_id')
@@ -133,7 +133,7 @@ def test_error_send_sticker_empty_file_id(self):
133133
lambda: self._bot.sendSticker(chat_id=self._chat_id,
134134
**json_dict))
135135

136-
@flaky
136+
@flaky(3, 1)
137137
@timeout(10)
138138
def test_error_sticker_without_required_args(self):
139139
print('Testing bot.sendSticker - Without required arguments')

0 commit comments

Comments
 (0)
X Tutup