tungwaiyip/HTMLTestRunner — pull request #5 by dwurf (2012-06-15 01:32:17+00:00)
Title: Prevent crash on class- or module-level exceptions

Hi,

This patch fixes a crash in HTMLTestRunner when a class-level or module-level exception is thrown. Below is a test case demonstrating the crash:

import sys
sys.path.append('.') # Location of HTMLTestRunner

import unittest
import HTMLTestRunner

def setUpModule():
# This causes HTMLTestRunner to fail
raise Exception('Module-level exception')

class HTMLTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
# This causes HTMLTestRunner to fail
raise Exception('Class-level exception')

def test_true(self):
"Verifies that the value of True hasn't changed"
self.assertTrue(True)

if __name__ == '__main__':
case = unittest.TestLoader().loadTestsFromTestCase(HTMLTestCase)
HTMLTestRunner.HTMLTestRunner().run(case)