How could I write the junit XML to a local file?

Asked by Kevin Chow

Thanks! I could get writing junit file to the screen by:

suite = unittest.TestLoader().loadTestsFromTestCase(myTestCase)
result = junitxml.JUnitXmlResult(sys.stdout)
result.startTestRun()
suite.run(result)
result.stopTestRun()

How could I modify so it would write the result to Local File instead? Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
pyjunitxml Edit question
Assignee:
No assignee Edit question
Solved by:
Kevin Chow
Solved:
Last query:
Last reply:
Revision history for this message
Kevin Chow (kevinckw) said :
#1

Hello,

Problem is solved and I could write it to the File Stream like this:

suite = unittest.TestLoader().loadTestsFromTestCase(myTestCase)
filename = "TestResult.xml"
FILE = open(filename, "w", 0)
result = junitxml.JUnitXmlResult(FILE)
result.startTestRun()
suite.run(result)
result.stopTestRun()