我有一组在python unittest框架中成功运行的测试用例。现在,我想以xml格式报告结果,或者以更具可读性和可导出性的方式报告给jenkins-jira-zephyr。
unittest中的以下testRunner成功执行,但最后显示与run方法有关的错误。如果我删除了.run(suite)
,就不会执行任何测试用例。
unittest.main(
testRunner=xmlrunner.XMLTestRunner(output='test-reports', verbosity=2).run(suite),
# these make sure that some options that are not applicable
# remain hidden from the help menu.
failfast=False, buffer=False, catchbreak=False)
错误是:
Traceback (most recent call last):
File "SuiteMediaAnalyticsMobile.py", line 31, in <module>
failfast=False, buffer=False, catchbreak=False)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 95, in __init__
self.runTests()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 232, in runTests
self.result = testRunner.run(self.test)
AttributeError: '_XMLTestResult' object has no attribute 'run'
如何让XMLTestRunner知道run(suite)仅适用于运行程序,而不适用于结果对象。否则,请避免此AttributeError。