[英]How to generate xml test report with stdout of unittest?
Assume I have a python tool to build and run unittest
, eg python3 build_and_test ...
. 假设我有一个python工具来构建和运行
unittest
,例如python3 build_and_test ...
Is there any way to parse stdout of unittest
and generate xml(junit) report? 有没有办法解析
unittest
stdout并生成xml(junit)报告? I have refer to unittest-xml-reporting
, but it seems that I must change my build_and_test
code and I can't do that. 我已经参考了
unittest-xml-reporting
,但似乎我必须更改build_and_test
代码而我不能这样做。 How can I just parse the stdout of unittest
and create xml reports? 我怎样才能解析
unittest
的stdout并创建xml报告?
You need to take 2 steps: 你需要采取两个步骤:
Extend unittest.TextTestRunner and override _makeResult(). 扩展unittest.TextTestRunner并覆盖_makeResult()。 See https://docs.python.org/3.4/library/unittest.html#unittest.TextTestRunner._makeResult
请参阅https://docs.python.org/3.4/library/unittest.html#unittest.TextTestRunner._makeResult
Implement your own version of unittest.TestResult. 实现您自己的unittest.TestResult版本。 See https://docs.python.org/3.4/library/unittest.html#unittest.TestResult .
请参阅https://docs.python.org/3.4/library/unittest.html#unittest.TestResult 。 Your code will be code upon various events.
您的代码将是各种活动的代码。 Example: When there is a testing error the methid addError will be called.
示例:当存在测试错误时,将调用methid addError。 See https://docs.python.org/3.4/library/unittest.html#unittest.TestResult.addError
请参阅https://docs.python.org/3.4/library/unittest.html#unittest.TestResult.addError
Now you have control of the various events and you will be able to create the XML report. 现在您可以控制各种事件,并且您将能够创建XML报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.