unittest / pdb tricks?
Alex
new_name at mit.edu
Tue Aug 28 17:56:17 EDT 2001
Hi, Sam. Below is the subclass of TestCase that I use to make unittests
throw an exception and drop back into the interpreter when they fail.
You can turn this behaviour off on a case-by-case basis by overriding
the value of __stopOnError__. I find it useful to do that for some
tests whose failures don't indicate such urgent problems, like the CVS
repository not being completely up-to-date.
Alex.
class TestCase(unittest.TestCase):
"""Version of TestCase that can be easily run independantly of the
testing framework."""
__stopOnError__ = 1
def __init__(self, *args, **kw):
if args: apply(unittest.TestCase.__init__, (self,) + args, kw)
def throwsException(self, test_function, expected_exc):
"""True if 'test_function()' throws 'expected_exc'"""
try: test_function()
except expected_exc: return 1
def __call__(self, result=None):
if self.__stopOnError__:
result.startTest(self)
self.setUp(); self.__testMethod(); self.tearDown();
print
else:
unittest.TestCase.__call__(self, result)
More information about the Python-list
mailing list