Skip to content

Commit 669f204

Browse files
charettesdnozay
authored andcommitted
Correctly handle partial test methods in startTest. (#187)
1 parent fffff9a commit 669f204

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/testsuite.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,25 @@ def test_test_program_fail_wo_buffer(self):
762762
self.assertIn('should be printed', r[0].getvalue())
763763
self.assertNotIn('should be printed', r[1].getvalue())
764764

765+
def test_partialmethod(self):
766+
try:
767+
from functools import partialmethod
768+
except ImportError:
769+
raise unittest.SkipTest('functools.partialmethod is not available.')
770+
def test_partialmethod(test):
771+
pass
772+
class TestWithPartialmethod(unittest.TestCase):
773+
pass
774+
setattr(
775+
TestWithPartialmethod,
776+
'test_partialmethod',
777+
partialmethod(test_partialmethod),
778+
)
779+
suite = unittest.TestSuite()
780+
suite.addTest(TestWithPartialmethod('test_partialmethod'))
781+
self._test_xmlrunner(suite)
782+
783+
765784

766785
class DuplicateWriterTestCase(unittest.TestCase):
767786
def setUp(self):

xmlrunner/result.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ def startTest(self, test):
261261
test_class = type(test)
262262
# Note: inspect can get confused with decorators, so use class.
263263
self.filename = inspect.getsourcefile(test_class)
264+
# Handle partial and partialmethod objects.
265+
test_method = getattr(test_method, 'func', test_method)
264266
_, self.lineno = inspect.getsourcelines(test_method)
265267
finally:
266268
pass

0 commit comments

Comments
 (0)