mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-14 14:49:21 +01:00
Add a decorator to retry tests that fail often.
This commit is contained in:
parent
aa98d987a7
commit
0254d7b84d
23
src/test.py
23
src/test.py
@ -36,6 +36,7 @@ import time
|
||||
import shutil
|
||||
import urllib
|
||||
import unittest
|
||||
import functools
|
||||
import threading
|
||||
|
||||
from . import (callbacks, conf, drivers, httpserver, i18n, ircdb, irclib,
|
||||
@ -67,6 +68,28 @@ def cachingGetHelp(method, name=None, doc=None):
|
||||
return lastGetHelp
|
||||
callbacks.getHelp = cachingGetHelp
|
||||
|
||||
def retry(tries=3):
|
||||
assert tries > 0
|
||||
def decorator(f):
|
||||
@functools.wraps(f)
|
||||
def newf(self):
|
||||
try:
|
||||
f(self)
|
||||
except AssertionError as e:
|
||||
first_exception = e
|
||||
for _ in range(1, tries):
|
||||
try:
|
||||
f(self)
|
||||
except AssertionError as e:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
else:
|
||||
# All failed
|
||||
raise first_exception
|
||||
return newf
|
||||
return decorator
|
||||
|
||||
def getTestIrc():
|
||||
irc = irclib.Irc('test')
|
||||
# Gotta clear the connect messages (USER, NICK, etc.)
|
||||
|
@ -58,6 +58,7 @@ class I18nTestCase(SupyTestCase):
|
||||
multiline = '%s\n\n%s' % (msg_en, msg_en)
|
||||
self.assertEqual(_(multiline), multiline)
|
||||
|
||||
@retry()
|
||||
def testDocstring(self):
|
||||
self.assertEqual(foo.__doc__, msg_en)
|
||||
self.assertEqual(bar.__doc__, msg_en)
|
||||
|
@ -42,6 +42,7 @@ class FunctionsTestCase(SupyTestCase):
|
||||
channels = {'#foo': holder()}
|
||||
nick = 'foobar'
|
||||
|
||||
@retry()
|
||||
def testStandardSubstitute(self):
|
||||
f = ircutils.standardSubstitute
|
||||
msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
|
||||
|
Loading…
Reference in New Issue
Block a user