assertraises behaviour

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Jul 17 19:49:35 CEST 2012


> > 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..
> 
> The reason for that is that the unit testing framework catches and
> handles the error. It calls both test functions in some unspecified
> order and logs the result. Calls to two separate test functions are
> thereby separated from each other. This is intentionally so, but I think
> you can also give the unit testing framework a flag that makes it abort
> after the first error. In no way will the exception escape from the
> unittest.main() call though, it is all caught and handled inside, also
> by intention.
> 
> 
> > But that's probably easy because we just need to catch exceptions for
> > every method call, so it's not exactly the same thing..
> 
> I don't understand what you want to say here. I also don't understand
> what your problem in general is. I guess there are some expectations
> which are not satisfied, but you haven't explained those explicitly yet.
>

I think Andrea wants to do the same thing but with nose and not
unittest.

Ramit

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list