Unittest - testing properties (read-only attributes)

Paul Rubin http
Mon Feb 21 12:25:05 EST 2005


Peter Hansen <peter at engcorp.com> writes:
> > 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...

Yes, assignment expressions could make code more readable, if Python
supported them.



More information about the Python-list mailing list