Re: [Pyunit-interest] assertRaises question
Brought to you by:
purcell
From: Steve P. <ste...@ya...> - 2002-05-31 07:19:30
|
in...@mj... wrote: > according to the documenation, assertRaises expects a function to test > as a 2nd argument > > now I want to test if > addr = Address() > addr.email = "wrong" > > raises an Exception. how can I test this with assertRaises ??? Short answer: you can't, unless you wrap it in a function. Longer answer: generally one would just code this as follows: addr = Address() try: addr.email = 'wrong' except IllegalFormatException: pass else: self.fail() But in your case you also could do this: self.assertRaises(IllegalFormatException, setattr, (addr, 'email', 'wrong')) Hope that helps, -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ |