diff --git a/tests/django_example/app/tests.py b/tests/django_example/app/tests.py index 232d365..663a858 100644 --- a/tests/django_example/app/tests.py +++ b/tests/django_example/app/tests.py @@ -4,4 +4,13 @@ # Create your tests here. class DummyTestCase(TestCase): def test_pass(self): + """Test Pass""" + pass + + def test_negative_comment1(self): + """Use a close comment XML tag -->""" + pass + + def test_negative_comment2(self): + """Check XML tag """ pass diff --git a/tests/django_test.py b/tests/django_test.py index be5feaa..4695c24 100644 --- a/tests/django_test.py +++ b/tests/django_test.py @@ -57,12 +57,16 @@ def _check_runner(self, runner): test_ids = [test.id() for test in suite] self.assertEqual(test_ids, [ 'app2.tests.DummyTestCase.test_pass', + 'app.tests.DummyTestCase.test_negative_comment1', + 'app.tests.DummyTestCase.test_negative_comment2', 'app.tests.DummyTestCase.test_pass', ]) suite = runner.build_suite(test_labels=[]) test_ids = [test.id() for test in suite] self.assertEqual(set(test_ids), set([ 'app.tests.DummyTestCase.test_pass', + 'app.tests.DummyTestCase.test_negative_comment1', + 'app.tests.DummyTestCase.test_negative_comment2', 'app2.tests.DummyTestCase.test_pass', ])) diff --git a/xmlrunner/result.py b/xmlrunner/result.py index d3b7722..fb81fd6 100644 --- a/xmlrunner/result.py +++ b/xmlrunner/result.py @@ -128,7 +128,7 @@ class _TestInfo(object): SKIP: 'skipped', } - def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=None, filename=None, lineno=None): + def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=None, filename=None, lineno=None, doc=None): self.test_result = test_result self.outcome = outcome self.elapsed_time = 0 @@ -159,6 +159,7 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest= self.filename = filename self.lineno = lineno + self.doc = doc def id(self): return self.test_id @@ -200,6 +201,7 @@ def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1, self.properties = properties # junit testsuite properties self.filename = None self.lineno = None + self.doc = None if infoclass is None: self.infoclass = _TestInfo else: @@ -213,6 +215,7 @@ def _prepare_callback(self, test_info, target_list, verbose_str, """ test_info.filename = self.filename test_info.lineno = self.lineno + test_info.doc = self.doc target_list.append(test_info) def callback(): @@ -258,6 +261,8 @@ def startTest(self, test): # Handle partial and partialmethod objects. test_method = getattr(test_method, 'func', test_method) _, self.lineno = inspect.getsourcelines(test_method) + + self.doc = test_method.__doc__ except (AttributeError, IOError, TypeError): # issue #188, #189, #195 # some frameworks can make test method opaque. @@ -555,6 +560,12 @@ def _report_testcase(test_result, xml_testsuite, xml_document): if test_result.lineno is not None: testcase.setAttribute('line', str(test_result.lineno)) + if test_result.doc is not None: + comment = str(test_result.doc) + # The use of '--' is forbidden in XML comments + comment = comment.replace('--', '--') + testcase.appendChild(xml_document.createComment(comment)) + result_elem_name = test_result.OUTCOME_ELEMENTS[test_result.outcome] if result_elem_name is not None: