Skip to content

Commit cbbb6f2

Browse files
munkyudnozay
authored andcommitted
Fix local variable 'xml_content' referenced before assignment
1 parent 77e9a52 commit cbbb6f2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

tests/testsuite.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,15 @@ def test_xmlrunner_stream(self):
575575
suite.addTest(self.DummyTest('test_pass'))
576576
runner.run(suite)
577577

578+
def test_xmlrunner_stream_empty_testsuite(self):
579+
stream = self.stream
580+
output = BytesIO()
581+
runner = xmlrunner.XMLTestRunner(
582+
stream=stream, output=output, verbosity=self.verbosity,
583+
**self.runner_kwargs)
584+
suite = unittest.TestSuite()
585+
runner.run(suite)
586+
578587
def test_xmlrunner_output_subdir(self):
579588
stream = self.stream
580589
output = os.path.join(self.outdir, 'subdir')

xmlrunner/result.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,12 @@ def generate_reports(self, test_runner):
605605
testsuite = _XMLTestResult._report_testsuite(
606606
suite_name, tests, doc, parentElement, self.properties
607607
)
608-
xml_content = doc.toprettyxml(
609-
indent='\t',
610-
encoding=test_runner.encoding
611-
)
612608

613609
if outputHandledAsString:
610+
xml_content = doc.toprettyxml(
611+
indent='\t',
612+
encoding=test_runner.encoding
613+
)
614614
filename = path.join(
615615
test_runner.output,
616616
'TEST-%s.xml' % suite_name)
@@ -621,6 +621,10 @@ def generate_reports(self, test_runner):
621621

622622
if not outputHandledAsString:
623623
# Assume that test_runner.output is a stream
624+
xml_content = doc.toprettyxml(
625+
indent='\t',
626+
encoding=test_runner.encoding
627+
)
624628
test_runner.output.write(xml_content)
625629

626630
def _exc_info_to_string(self, err, test):

0 commit comments

Comments
 (0)