I love assert

Terry Reedy tjreedy at udel.edu
Wed Nov 12 03:29:13 EST 2014


On 11/11/2014 5:52 PM, Ben Finney wrote:
> Terry Reedy <tjreedy at udel.edu> writes:
>
>> We love 'assert' so much that we have 20-30 'assertXYZ' variations in
>> unittest.
>
> A function will not be disabled by a run-time option to the Python
> interpreter.
>
>> The statement 'assert expression' is almost equivalent to
>>
>> if not expression: raise AssertionError('expression')
>
> With the important difference that this will be active no matter what
> options Python's interpreter is run with. That makes it quite a
> different proposition from using ‘assert’ statements.

Which importand difference I pointed out (and you snipped) as a reason 
to seldom use bare assert.

-- 
Terry Jan Reedy





More information about the Python-list mailing list