> On 3 Mar 2021, at 18:41, Chris Angelico <ros...@gmail.com> wrote:
> 
> On Thu, Mar 4, 2021 at 5:25 AM Barry Scott <ba...@barrys-emacs.org 
> <mailto:ba...@barrys-emacs.org>> wrote:
>> 
>> 
>> 
>>> On 3 Mar 2021, at 17:35, David Lowry-Duda <da...@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)
>> 
> 
> That doesn't look like the sort of thing that should be an assertion.
> Assertions should be for things that, if your code were bug-free,
> could never happen.

If the code works the status will be 200 and the test will pass.

Now you can argue that the test suite should use something better then assert,
but assert is what the code that I inherited uses. Its origins go back many many
years. Its would be a lot of work to modernise as there are 1,000s of test 
suites
affect.

Barry


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

Reply via email to