From bcae62c6824612cb0fc9d996f4a8a6ee14cd9394 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 27 Sep 2017 13:56:19 +0530 Subject: [PATCH] issue #20: TestCase subclass with a nicer assertRaises --- tests/testlib.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/testlib.py b/tests/testlib.py index caf7297d..729461f8 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -28,6 +28,19 @@ def data_path(suffix): return path +class TestCase(unittest.TestCase): + def assertRaises(self, exc, func, *args, **kwargs): + """Like regular assertRaises, except return the exception that was + raised. Can't use context manager because tests must run on Python2.4""" + try: + func(*args, **kwargs) + except exc, e: + return e + except BaseException, e: + assert 0, '%r raised %r, not %r' % (func, e, exc) + assert 0, '%r did not raise %r' % (func, exc) + + class DockerizedSshDaemon(object): def __init__(self): self.docker = docker.from_env()