【发布时间】:2015-04-29 13:56:03
【问题描述】:
我正在 python 中使用 XMLrunner 和 unittest 编写一个简单的测试。使用断言时,测试失败并且不会继续。我希望测试继续到最后,然后失败。是否可以?我将附上一个非常简单的代码来演示我需要做什么。
import xmlrunner
import unittest
class TestExp(unittest.TestCase):
def setUp(self):
self.list = range(1,10)
def test_example(self):
for i in self.list:
self.assertTrue(i == 3, str(i) + "message")
if __name__ == '__main__':
unittest.main(
testRunner=xmlrunner.XMLTestRunner(output='test-reports'),
failfast=False, buffer=False, catchbreak=False)
作为输出生成一个 XML,但是只包含第一个失败的断言,我需要运行其余的断言并从它们生成测试报告,当使用 try/except 时,我看不到测试用例在 XML 中失败文件。
<?xml version="1.0" ?>
<testsuite errors="1" failures="0" name="TestExp-20150429152621" tests="1" time="0.000">
<testcase classname="TestExp" name="test_example" time="0.000">
<error message="1message" type="AssertionError">
<![CDATA[Traceback (most recent call last):
File "xmlrunsample.py", line 14, in test_example
self.assertTrue(i == 3, str(i) + "message")
AssertionError: 1message
]]> </error>
</testcase>
<system-out>
<![CDATA[]]> </system-out>
<system-err>
<![CDATA[]]> </system-err>
</testsuite>
这是我得到的测试报告输出,仅包含 1 个断言失败,我怎样才能让脚本继续断言其余的测试用例?
【问题讨论】:
标签: python xml unit-testing jenkins