mardi 26 mai 2015

How to prevent unittest exiting on failure

I'm attempting to write a test suite which doesn't exit on failure. Take the following example:

class MyTestSuite(unittest.TestCase):

    def test_foo(self):
        self.assert_equal(1, 2)
        print('bar')
        self.assert_equal(5, 5)

if __name__ == "__main__":
    unittest.main(failfast=False, exit=False)

'bar' isn't printed due to the first assertion failing.

How do I prevent unittest exiting on failure?

Research

  • failfast=True causes the whole test run to quit on a failure and defaults to False so this doesn't help.
  • According to the docs exit=False doesn't help as it simply switches between standard output and calling sys.exit().
  • It looks like I may need to override the unittest package but where to start?

Aucun commentaire:

Enregistrer un commentaire