From 8dbc04aa06e0cbcb951f489393e81638c150e577 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 29 Oct 2014 13:30:24 +0100 Subject: [PATCH] Test cases fixed: testFail2BanExceptHook - use local sys.__excepthook__ to check was really executed and prevent write error in stderr. --- fail2ban/tests/servertestcase.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 062284f7..362f4253 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -804,7 +804,7 @@ class RegexTests(unittest.TestCase): class _BadThread(JailThread): def run(self): - int("ignore this exception -- raised for testing") + raise RuntimeError('run bad thread exception') class LoggingTests(LogCaptureTestCase): @@ -814,7 +814,13 @@ class LoggingTests(LogCaptureTestCase): self.assertEqual(testLogSys.name, "fail2ban.name") def testFail2BanExceptHook(self): + prev_exchook = sys.__excepthook__ + x = [] + sys.__excepthook__ = lambda *args: x.append(args) badThread = _BadThread() badThread.start() badThread.join() self.assertTrue(self._is_logged("Unhandled exception")) + sys.__excepthook__ = prev_exchook + self.assertEqual(len(x), 1) + self.assertEqual(x[0][0], RuntimeError)