Skip to content

Commit 0fde905

Browse files
committed
fix #195
1 parent 4ab171c commit 0fde905

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

tests/testsuite.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from xmlrunner.result import _XMLTestResult
1616
import doctest
1717
import tests.doctest_example
18-
from six import StringIO, BytesIO
18+
from six import StringIO, BytesIO, exec_
1919
from tempfile import mkdtemp
2020
from tempfile import mkstemp
2121
from shutil import rmtree
@@ -107,6 +107,17 @@ def _strip_xml(xml, changes):
107107
return etree.tostring(doc)
108108

109109

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+
110121
class XMLTestRunnerTestCase(unittest.TestCase):
111122
"""
112123
XMLTestRunner test case.
@@ -187,6 +198,12 @@ def test_subTest_mixed(self):
187198
with self.subTest(i=i):
188199
self.assertLess(i, 1, msg='this is a subtest.')
189200

201+
class DecoratedUnitTest(unittest.TestCase):
202+
203+
@some_decorator
204+
def test_pass(self):
205+
pass
206+
190207
class DummyErrorInCallTest(unittest.TestCase):
191208

192209
def __call__(self, result):
@@ -712,6 +729,13 @@ def test_xmlrunner_patched_stdout(self):
712729
finally:
713730
sys.stdout, sys.stderr = old_stdout, old_stderr
714731

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+
715739
def test_xmlrunner_error_in_call(self):
716740
suite = unittest.TestSuite()
717741
suite.addTest(self.DummyErrorInCallTest('test_pass'))

xmlrunner/result.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ def startTest(self, test):
271271
# Handle partial and partialmethod objects.
272272
test_method = getattr(test_method, 'func', test_method)
273273
_, self.lineno = inspect.getsourcelines(test_method)
274-
except (AttributeError, TypeError):
275-
# issue #188, #189, some frameworks can make test method opaque.
274+
except (AttributeError, IOError, TypeError):
275+
# issue #188, #189, #195
276+
# some frameworks can make test method opaque.
276277
pass
277278

278279
if self.showAll:

0 commit comments

Comments
 (0)