assertraises behaviour

Terry Reedy tjreedy at udel.edu
Tue Jul 17 14:39:12 EDT 2012


On 7/17/2012 5:06 AM, andrea crotti wrote:

> Well this is what I meant:
>
> import unittest
>
> class TestWithRaises(unittest.TestCase):
>      def test_first(self):
>          assert False
>
>      def test_second(self):
>          print("also called")
>          assert True
>
> if __name__ == '__main__':
>      unittest.main()
>
> in this case also the second test is run even if the first fails.

Or test_first is run even if test_second fails. The point is that 
unittest runs separate test methods independently. They could 
theoretically be run simultaneously.

Tests within a method are dependent unless you take steps to make them 
independent by not having them raise exceptions or by catching exception 
as you go until you are done. If you make a error_list of problems as 
you go, you could end the method with assertFalse(error_list).

-- 
Terry Jan Reedy






More information about the Python-list mailing list