@@ -128,7 +128,7 @@ class _TestInfo(object):
128
128
SKIP : 'skipped' ,
129
129
}
130
130
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 ):
132
132
self .test_result = test_result
133
133
self .outcome = outcome
134
134
self .elapsed_time = 0
@@ -159,6 +159,7 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=
159
159
160
160
self .filename = filename
161
161
self .lineno = lineno
162
+ self .doc = doc
162
163
163
164
def id (self ):
164
165
return self .test_id
@@ -200,6 +201,7 @@ def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1,
200
201
self .properties = properties # junit testsuite properties
201
202
self .filename = None
202
203
self .lineno = None
204
+ self .doc = None
203
205
if infoclass is None :
204
206
self .infoclass = _TestInfo
205
207
else :
@@ -213,6 +215,7 @@ def _prepare_callback(self, test_info, target_list, verbose_str,
213
215
"""
214
216
test_info .filename = self .filename
215
217
test_info .lineno = self .lineno
218
+ test_info .doc = self .doc
216
219
target_list .append (test_info )
217
220
218
221
def callback ():
@@ -258,6 +261,8 @@ def startTest(self, test):
258
261
# Handle partial and partialmethod objects.
259
262
test_method = getattr (test_method , 'func' , test_method )
260
263
_ , self .lineno = inspect .getsourcelines (test_method )
264
+
265
+ self .doc = test_method .__doc__
261
266
except (AttributeError , IOError , TypeError ):
262
267
# issue #188, #189, #195
263
268
# some frameworks can make test method opaque.
@@ -555,6 +560,12 @@ def _report_testcase(test_result, xml_testsuite, xml_document):
555
560
if test_result .lineno is not None :
556
561
testcase .setAttribute ('line' , str (test_result .lineno ))
557
562
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
+
558
569
result_elem_name = test_result .OUTCOME_ELEMENTS [test_result .outcome ]
559
570
560
571
if result_elem_name is not None :
0 commit comments