mercredi 29 avril 2015

continue test after assertion fail using xmlrunner and unittest in python

I am writing a simple test using XMLrunner and unittest in python. When using assert the test fails and does not continue. I want the test to continue to the end and then fail. Is it possible? I will attach a very simple code demostrating what I need to do.

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)

as an output an XML is generated, however containing only the first failed assertion, I need to run the rest of the assertions and also generate test-reports from them, when using try/except i cannot see the 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 is what i get as test-report output, containing only 1 assertion fail, how can i make the script continue to assert the rest of test cases?

Aucun commentaire:

Enregistrer un commentaire