@@ -128,7 +128,7 @@ class _TestInfo(object):
128128 SKIP : 'skipped' ,
129129 }
130130
131- def __init__ (self , test_result , test_method , outcome = SUCCESS , err = None , subTest = None , filename = None , lineno = None ):
131+ def __init__ (self , test_result , test_method , outcome = SUCCESS , err = None , subTest = None , filename = None , lineno = None , doc = None ):
132132 self .test_result = test_result
133133 self .outcome = outcome
134134 self .elapsed_time = 0
@@ -159,6 +159,7 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=
159159
160160 self .filename = filename
161161 self .lineno = lineno
162+ self .doc = doc
162163
163164 def id (self ):
164165 return self .test_id
@@ -200,6 +201,7 @@ def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1,
200201 self .properties = properties # junit testsuite properties
201202 self .filename = None
202203 self .lineno = None
204+ self .doc = None
203205 if infoclass is None :
204206 self .infoclass = _TestInfo
205207 else :
@@ -213,6 +215,7 @@ def _prepare_callback(self, test_info, target_list, verbose_str,
213215 """
214216 test_info .filename = self .filename
215217 test_info .lineno = self .lineno
218+ test_info .doc = self .doc
216219 target_list .append (test_info )
217220
218221 def callback ():
@@ -258,6 +261,8 @@ def startTest(self, test):
258261 # Handle partial and partialmethod objects.
259262 test_method = getattr (test_method , 'func' , test_method )
260263 _ , self .lineno = inspect .getsourcelines (test_method )
264+
265+ self .doc = test_method .__doc__
261266 except (AttributeError , IOError , TypeError ):
262267 # issue #188, #189, #195
263268 # some frameworks can make test method opaque.
@@ -555,6 +560,12 @@ def _report_testcase(test_result, xml_testsuite, xml_document):
555560 if test_result .lineno is not None :
556561 testcase .setAttribute ('line' , str (test_result .lineno ))
557562
563+ if test_result .doc is not None :
564+ comment = str (test_result .doc )
565+ # The use of '--' is forbidden in XML comments
566+ comment = comment .replace ('--' , '--' )
567+ testcase .appendChild (xml_document .createComment (comment ))
568+
558569 result_elem_name = test_result .OUTCOME_ELEMENTS [test_result .outcome ]
559570
560571 if result_elem_name is not None :
0 commit comments