Unittest - testing properties (read-only attributes)

Paul Rubin http
Mon Feb 21 12:42:14 EST 2005


Duncan Booth <duncan.booth at invalid.invalid> writes:
> An assignment expression, if such a thing existed wouldn't help here.
> 
> The point being that the expression must be evaluated inside the exception 
> handler in assertRaises, so you either need to delay the evaluation with a 
> lambda, or by passing the function and arguments in separately. If you had 
> an assignment expression it would be roughly equivalent to:
> 
>    self.assertRaises(AttributeError, setattr(self.combat, 'value', 1))
> 
> which will throw the AttributeError instead of passing the test.

Yes.  The example I quoted used an assignment expression inside a
lambda.  The person who posted it, and the person who followed it up
with the setattr alternative, both didn't notice that the assignment
expression wasn't valid Python.  However, my post came out sounding
grumpier than I intended ;).



More information about the Python-list mailing list