Unittest - testing properties (read-only attributes)

Paul Moore pf_moore at yahoo.co.uk
Mon Feb 21 12:33:34 EST 2005


Peter Hansen <peter at engcorp.com> writes:

> Roy Smith wrote:
>> You want something like
>> self.assertRaises(AttributeError, lambda: self.combat.value = 1)
>
> Or, combining the two responses and avoiding the lambda:
>
>  self.assertRaises(AttributeError, setattr, self.combat, 'value', 1)
>
> Hmm... this might be a case where the lambda form is actually the
> more readable one...

Thanks, I hadn't thought of setattr. I was bitten by the "assignment
is a statement, so can't be used in a lambda" issue, as well :-)

Paul.
-- 
It was a machine, and as such only understood one thing. Being clobbered
with big hammers was something it could relate to. -- Tom Holt



More information about the Python-list mailing list