diff options
| author | Thomi Richards <thomir@gmail.com> | 2014-03-05 10:00:45 +1300 |
|---|---|---|
| committer | Thomi Richards <thomir@gmail.com> | 2014-03-10 15:40:55 +1300 |
| commit | 431aafb3ec39c7769fd83d2d5969a1875c9a8c5b (patch) | |
| tree | 20987e68db5d3a874b7708d14fe501e110fae264 /testtools/testcase.py | |
| parent | 37423310ecc1da58f0aac92f33c688f4ba3e01e9 (diff) | |
| download | testtools-431aafb3ec39c7769fd83d2d5969a1875c9a8c5b.tar.gz | |
Added failing test for python 3.4 unittest.expectedFailure decorator changes.
Diffstat (limited to 'testtools/testcase.py')
| -rw-r--r-- | testtools/testcase.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/testtools/testcase.py b/testtools/testcase.py index 96be47c..7b22cbf 100644 --- a/testtools/testcase.py +++ b/testtools/testcase.py @@ -16,6 +16,7 @@ __all__ = [ ] import copy +import functools import itertools import sys import types @@ -83,6 +84,20 @@ _ExpectedFailure = try_import( 'unittest.case._ExpectedFailure', _ExpectedFailure) +# Copied from unittest before python 3.4 release. Used to maintain +# compatibility with unittest sub-test feature. Users should not use this +# directly. +def _expectedFailure(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + try: + func(*args, **kwargs) + except Exception: + raise _ExpectedFailure(sys.exc_info()) + raise _UnexpectedSuccess + return wrapper + + def run_test_with(test_runner, **kwargs): """Decorate a test as using a specific ``RunTest``. @@ -192,6 +207,8 @@ class TestCase(unittest.TestCase): runTest = getattr( test_method, '_run_test_with', self.run_tests_with) self.__RunTest = runTest + if getattr(test_method, '__unittest_expecting_failure__', False): + setattr(self, self._testMethodName, _expectedFailure(test_method)) self.__exception_handlers = [] self.exception_handlers = [ (self.skipException, self._report_skip), |
