xml - continue test after assertion fail using xmlrunner and unittest in python -
i writing simple test using xmlrunner , unittest in python. when using assert test fails , not continue. want test continue end , fail. possible? attach simple code demostrating need do.
import xmlrunner import unittest class testexp(unittest.testcase): def setup(self): self.list = range(1,10) def test_example(self): 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)
as output xml generated, containing first failed assertion, need run rest of assertions , generate test-reports them, when using try/except cannot see testcase fail in xml file.
<?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>
this test-report output, containing 1 assertion fail, how can make script continue assert rest of test cases?
you structuring tests wrong way. test runner sees single test. when catches assertion, test failes.
if want stay close code, have catch assertions yourself, , re-throw 1 in end. smelly code, makes origin of fail opaque.
ideally you'd have re-engineer tests. if have assertions independent of each other (i.e. interested in next one, if previous failed), have independent test cases. testrunner responsible iteration through tests, , catch each assertion , output it.
look @ the fine documentation on how it.
if looking parametrized test cases, here on so idea, on can start.
Comments
Post a Comment