Why assert is not a function?

Barry Scott barry at barrys-emacs.org
Wed Mar 3 13:24:21 EST 2021



> On 3 Mar 2021, at 17:35, David Lowry-Duda <david at lowryduda.com> wrote:
> 
>> assert condition, expression
>> 
>> Only is condition is false with expression be evaluated.
>> So you can safely do expensive things I the expression with incuring 
>> and cost if the condition is True.
> 
> I think I've only every used a string as the expression. Have you found 
> it useful to use complicated, expensive expressions? Could you give an 
> example?

In the test suite of the product I work on its common to put a lot of information into the expression.
For example if a HTTP request returns unexpected content we will include all the headers and
body of the that the request returners.

	assert http_status == '200', 'Request failed status %r Body:\n%s' % (http_status, http_header_and_body)

Barry


> 
> - DLD
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list