[docs] suggestion for http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises
Andrew Hammond
andrew.george.hammond at gmail.com
Tue Apr 19 23:24:35 CEST 2011
Yeah, that looks perfect.
On Tuesday, April 19, 2011, Sandro Tosi <sandro.tosi at gmail.com> wrote:
> Hi Andrew,
>> On Wed, Mar 9, 2011 at 21:52, Andrew Hammond
> <andrew.george.hammond at gmail.com> wrote:
>> I suggest adding an example of using assertRaises to test a property:
>>>> class MyObject(object):
>> @property
>> def myProperty():
>> raise Exception()
>>>> self.assertRaises(Exception, getattr, myObject, myProperty)
>>>> Rationale: the naive approach doesn't work and I spent a good half
>> hour figuring that out.
>> can you confirm you want something like:
>> class MyObject(object):
> @property
> def myProperty(self):
> raise Exception()
>> ...
> myObject = MyObject()
> self.assertRaises(Exception, getattr, myObject, 'myProperty')
>> ?
>> f.e:
>>>> getattr(myObject, 'myProperty')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 4, in myProperty
> Exception
>> Else I can't get it to work.
>> Regards,
> --
> Sandro Tosi (aka morph, morpheus, matrixhasu)
> My website: http://matrixhasu.altervista.org/
> Me at Debian: http://wiki.debian.org/SandroTosi
>
More information about the docs
mailing list