@@ -170,6 +170,10 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=
170170 self .lineno = lineno
171171 self .doc = doc
172172
173+ # 'test_method' actually represents the test class that will lead to a
174+ # 'testsuite' XML node
175+ self .suite_doc = test_method .__doc__
176+
173177 def id (self ):
174178 return self .test_id
175179
@@ -465,8 +469,11 @@ def _get_info_by_testcase(self):
465469 test_info = test_info [0 ]
466470 testcase_name = test_info .test_name
467471 if testcase_name not in tests_by_testcase :
468- tests_by_testcase [testcase_name ] = []
469- tests_by_testcase [testcase_name ].append (test_info )
472+ tests_by_testcase [testcase_name ] = {
473+ 'suite_doc' : test_info .suite_doc ,
474+ 'tests' : []
475+ }
476+ tests_by_testcase [testcase_name ]['tests' ].append (test_info )
470477
471478 return tests_by_testcase
472479
@@ -482,7 +489,7 @@ def _report_testsuite_properties(xml_testsuite, xml_document, properties):
482489
483490 _report_testsuite_properties = staticmethod (_report_testsuite_properties )
484491
485- def _report_testsuite (suite_name , tests , xml_document , parentElement ,
492+ def _report_testsuite (suite_name , suite_doc , tests , xml_document , parentElement ,
486493 properties ):
487494 """
488495 Appends the testsuite section to the XML document.
@@ -512,6 +519,12 @@ def _report_testsuite(suite_name, tests, xml_document, parentElement,
512519 skips = filter (lambda e : e .outcome == _TestInfo .SKIP , tests )
513520 testsuite .setAttribute ('skipped' , str (len (list (skips ))))
514521
522+ if suite_doc :
523+ comment = str (suite_doc )
524+ # The use of '--' is forbidden in XML comments
525+ comment = comment .replace ('--' , '--' )
526+ testsuite .appendChild (xml_document .createComment (safe_unicode (comment )))
527+
515528 _XMLTestResult ._report_testsuite_properties (
516529 testsuite , xml_document , properties )
517530
@@ -633,7 +646,10 @@ def generate_reports(self, test_runner):
633646 doc .appendChild (testsuite )
634647 parentElement = testsuite
635648
636- for suite , tests in all_results .items ():
649+ for suite , suite_info in all_results .items ():
650+ suite_doc = suite_info ['suite_doc' ]
651+ tests = suite_info ['tests' ]
652+
637653 if outputHandledAsString :
638654 doc = Document ()
639655 parentElement = doc
@@ -645,7 +661,7 @@ def generate_reports(self, test_runner):
645661
646662 # Build the XML file
647663 testsuite = _XMLTestResult ._report_testsuite (
648- suite_name , tests , doc , parentElement , self .properties
664+ suite_name , suite_doc , tests , doc , parentElement , self .properties
649665 )
650666
651667 if outputHandledAsString :
0 commit comments