|
15 | 15 | from xmlrunner.result import _XMLTestResult |
16 | 16 | import doctest |
17 | 17 | import tests.doctest_example |
18 | | -from six import StringIO, BytesIO |
| 18 | +from six import StringIO, BytesIO, exec_ |
19 | 19 | from tempfile import mkdtemp |
20 | 20 | from tempfile import mkstemp |
21 | 21 | from shutil import rmtree |
@@ -107,6 +107,17 @@ def _strip_xml(xml, changes): |
107 | 107 | return etree.tostring(doc) |
108 | 108 |
|
109 | 109 |
|
| 110 | +def some_decorator(f): |
| 111 | + # for issue #195 |
| 112 | + code = """\ |
| 113 | +def wrapper(*args, **kwargs): |
| 114 | + return func(*args, **kwargs) |
| 115 | +""" |
| 116 | + evaldict = dict(func=f) |
| 117 | + exec_(code, evaldict) |
| 118 | + return evaldict['wrapper'] |
| 119 | + |
| 120 | + |
110 | 121 | class XMLTestRunnerTestCase(unittest.TestCase): |
111 | 122 | """ |
112 | 123 | XMLTestRunner test case. |
@@ -187,6 +198,12 @@ def test_subTest_mixed(self): |
187 | 198 | with self.subTest(i=i): |
188 | 199 | self.assertLess(i, 1, msg='this is a subtest.') |
189 | 200 |
|
| 201 | + class DecoratedUnitTest(unittest.TestCase): |
| 202 | + |
| 203 | + @some_decorator |
| 204 | + def test_pass(self): |
| 205 | + pass |
| 206 | + |
190 | 207 | class DummyErrorInCallTest(unittest.TestCase): |
191 | 208 |
|
192 | 209 | def __call__(self, result): |
@@ -712,6 +729,13 @@ def test_xmlrunner_patched_stdout(self): |
712 | 729 | finally: |
713 | 730 | sys.stdout, sys.stderr = old_stdout, old_stderr |
714 | 731 |
|
| 732 | + def test_opaque_decorator(self): |
| 733 | + suite = unittest.TestSuite() |
| 734 | + suite.addTest(self.DecoratedUnitTest('test_pass')) |
| 735 | + self._test_xmlrunner(suite) |
| 736 | + testsuite_output = self.stream.getvalue() |
| 737 | + self.assertNotIn('IOError:', testsuite_output) |
| 738 | + |
715 | 739 | def test_xmlrunner_error_in_call(self): |
716 | 740 | suite = unittest.TestSuite() |
717 | 741 | suite.addTest(self.DummyErrorInCallTest('test_pass')) |
|
0 commit comments