From 0254d7b84d0ce442e3b0616c7e3b0aa9d3832f2a Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 11 Aug 2015 17:13:27 +0200 Subject: [PATCH] Add a decorator to retry tests that fail often. --- src/test.py | 23 +++++++++++++++++++++++ test/test_i18n.py | 1 + test/test_standardSubstitute.py | 1 + 3 files changed, 25 insertions(+) diff --git a/src/test.py b/src/test.py index 80bb67e33..adb6d4773 100644 --- a/src/test.py +++ b/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.) diff --git a/test/test_i18n.py b/test/test_i18n.py index a4f6582b6..3d2399c8e 100644 --- a/test/test_i18n.py +++ b/test/test_i18n.py @@ -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) diff --git a/test/test_standardSubstitute.py b/test/test_standardSubstitute.py index 3beb94a2a..901f6cb4e 100644 --- a/test/test_standardSubstitute.py +++ b/test/test_standardSubstitute.py @@ -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')