Home | History | Annotate | Download | only in unittests
      1 import unittest
      2 
      3 class BrokenTest(unittest.TestCase.failureException):
      4     def __repr__(self):
      5         name, reason = self.args
      6         return '%s: %s: %s works now' % (
      7             (self.__class__.__name__, name, reason))
      8 
      9 
     10 def broken(reason, *exceptions):
     11     '''Indicates a failing (or erroneous) test case fails that should succeed.
     12     If the test fails with an exception, list the exception type in args'''
     13     def wrapper(test_method):
     14         def replacement(*args, **kwargs):
     15             try:
     16                 test_method(*args, **kwargs)
     17             except exceptions or unittest.TestCase.failureException:
     18                 pass
     19             else:
     20                 raise BrokenTest(test_method.__name__, reason)
     21         replacement.__doc__ = test_method.__doc__
     22         replacement.__name__ = 'XXX_' + test_method.__name__
     23         replacement.todo = reason
     24         return replacement
     25     return wrapper
     26 
     27 
     28