Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25485

Re: assertraises behaviour

From Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Newsgroups comp.lang.python
Subject Re: assertraises behaviour
Date 2012-07-17 12:34 +0200
Message-ID <lmrfd9-he3.ln1@satorlaser.homedns.org> (permalink)
References (2 earlier) <CAF_E5JZNrusmb2SziNBOah67ioZG0yf_w5RNJxVVrU8B5Tqzuw@mail.gmail.com> <ju1att$hc4$1@dough.gmane.org> <CAF_E5Ja4kzHGa9vEr5CML5wV7ampCULRRGt=9JtRoqn4Xxummw@mail.gmail.com> <ju1iug$mtd$1@dough.gmane.org> <mailman.2206.1342515998.4697.python-list@python.org>

Show all headers | View raw


Am 17.07.2012 11:06, schrieb andrea crotti:
> 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.

Uli

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: assertraises behaviour andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-17 10:06 +0100
  Re: assertraises behaviour Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-17 12:34 +0200
    RE: assertraises behaviour "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-17 17:49 +0000
    Re: assertraises behaviour Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-07-17 19:03 +0100
    RE: assertraises behaviour "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-17 21:04 +0000

csiph-web