Add a decorator to retry tests that fail often.

This commit is contained in:
Valentin Lorentz 2015-08-11 17:13:27 +02:00
parent aa98d987a7
commit 0254d7b84d
3 changed files with 25 additions and 0 deletions

View File

@ -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.)

View File

@ -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)

View File

@ -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')