1 | import logging |
---|
2 | import unittest |
---|
3 | from traceback import format_tb |
---|
4 | |
---|
5 | log = logging.getLogger(__name__) |
---|
6 | |
---|
7 | |
---|
8 | __all__ = ['Failure'] |
---|
9 | |
---|
10 | |
---|
11 | class Failure(unittest.TestCase): |
---|
12 | """Unloadable or unexecutable test. |
---|
13 | |
---|
14 | A Failure case is placed in a test suite to indicate the presence of a |
---|
15 | test that could not be loaded or executed. A common example is a test |
---|
16 | module that fails to import. |
---|
17 | |
---|
18 | """ |
---|
19 | __test__ = False # do not collect |
---|
20 | def __init__(self, exc_class, exc_val, tb=None, address=None): |
---|
21 | log.debug("A failure! %s %s %s", exc_class, exc_val, format_tb(tb)) |
---|
22 | self.exc_class = exc_class |
---|
23 | self.exc_val = exc_val |
---|
24 | self.tb = tb |
---|
25 | self._address = address |
---|
26 | unittest.TestCase.__init__(self) |
---|
27 | |
---|
28 | def __str__(self): |
---|
29 | return "Failure: %s (%s)" % ( |
---|
30 | getattr(self.exc_class, '__name__', self.exc_class), self.exc_val) |
---|
31 | |
---|
32 | def address(self): |
---|
33 | return self._address |
---|
34 | |
---|
35 | def runTest(self): |
---|
36 | if self.tb is not None: |
---|
37 | raise self.exc_class, self.exc_val, self.tb |
---|
38 | else: |
---|
39 | raise self.exc_class(self.exc_val) |
---|