Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions tests/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_doctest_example(self):
runner.run(suite)
outdir.seek(0)
output = outdir.read()
# note: the testcases generated by DocTestSuite are not attached to where the docstring is declared.
# In other words, it does not preserve classname/package information.
self.assertIn('name="twice"'.encode('utf8'), output)
self.assertIn('name="threetimes"'.encode('utf8'), output)
self.assertIn('classname="tests.doctest_example.Multiplicator" name="threetimes"'
.encode('utf8'), output)
self.assertIn('classname="tests.doctest_example" name="twice"'
.encode('utf8'), output)


class XMLTestRunnerTestCase(unittest.TestCase):
Expand Down Expand Up @@ -123,6 +123,21 @@ def test_basic_unittest_constructs(self):
suite.addTest(self.DummyTest('test_error'))
self._test_xmlrunner(suite)

def test_classnames(self):
suite = unittest.TestSuite()
suite.addTest(self.DummyTest('test_pass'))
suite.addTest(self.DummySubTest('test_subTest_pass'))
outdir = BytesIO()
stream = StringIO()
runner = xmlrunner.XMLTestRunner(stream=stream, output=outdir, verbosity=0)
runner.run(suite)
outdir.seek(0)
output = outdir.read()
self.assertIn('classname="tests.testsuite.DummyTest" name="test_pass"'
.encode('utf8'), output)
self.assertIn('classname="tests.testsuite.DummySubTest" name="test_subTest_pass"'
.encode('utf8'), output)

def test_xmlrunner_non_ascii(self):
suite = unittest.TestSuite()
suite.addTest(self.DummyTest('test_non_ascii_skip'))
Expand Down
12 changes: 7 additions & 5 deletions xmlrunner/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _report_testsuite_properties(xml_testsuite, xml_document, properties):

_report_testsuite_properties = staticmethod(_report_testsuite_properties)

def _report_testsuite(suite_name, suite, tests, xml_document, parentElement,
def _report_testsuite(suite_name, tests, xml_document, parentElement,
properties):
"""
Appends the testsuite section to the XML document.
Expand All @@ -339,7 +339,7 @@ def _report_testsuite(suite_name, suite, tests, xml_document, parentElement,
testsuite, xml_document, properties)

for test in tests:
_XMLTestResult._report_testcase(suite, test, testsuite, xml_document)
_XMLTestResult._report_testcase(test, testsuite, xml_document)

systemout = xml_document.createElement('system-out')
testsuite.appendChild(systemout)
Expand Down Expand Up @@ -389,14 +389,16 @@ def _createCDATAsections(xmldoc, node, text):

_createCDATAsections = staticmethod(_createCDATAsections)

def _report_testcase(suite_name, test_result, xml_testsuite, xml_document):
def _report_testcase(test_result, xml_testsuite, xml_document):
"""
Appends a testcase section to the XML document.
"""
testcase = xml_document.createElement('testcase')
xml_testsuite.appendChild(testcase)

testcase.setAttribute('classname', suite_name)
class_name = re.sub(r'^__main__.', '', test_result.id())
class_name = class_name.rpartition('.')[0]
testcase.setAttribute('classname', class_name)
testcase.setAttribute(
'name', _XMLTestResult._test_method_name(test_result.test_id)
)
Expand Down Expand Up @@ -455,7 +457,7 @@ def generate_reports(self, test_runner):

# Build the XML file
testsuite = _XMLTestResult._report_testsuite(
suite_name, suite, tests, doc, parentElement, self.properties
suite_name, tests, doc, parentElement, self.properties
)
xml_content = doc.toprettyxml(
indent='\t',
Expand Down