I agree with Tim. He's also probably the most familiar with the cost of
message changes 😊

On 7 April 2017 at 12:56, Tim Graham <timogra...@gmail.com> wrote:

> Hi Shai,
>
> Without testing for a message, there's also a possibility that the
> exception you think you're testing isn't the one the test is actually
> raising. I think the readability advantages of including messages in the
> tests outweigh the cost of updating tests when a message changes.
>
>
> On Friday, April 7, 2017 at 5:30:25 AM UTC-4, Shai Berger wrote:
>>
>> Hello all,
>>
>> A recent PR[1] seeks to replace most of the assertRaises() calls in the
>> test-
>> suite with assertRaisesMessage(). The argument for it is that it then
>> becomes
>> easier to find the test for some error handling, by grepping the test for
>> the
>> message text. Also, in some cases, an existing assertRaises() is followed
>> by a
>> separate, explicit verification of the message text[2], which surely
>> indicates
>> that assertRaisesMessage() should have been used; and actually, this
>> whole
>> move initiated as part of the Py2-support-deprecation changes.
>>
>> However, I don't think we should generally prefer assertRaisesMessage to
>> assertRaises, because it means that trivial phrasing changes need to be
>> made
>> twice (at least) instead of once. I don't believe exception messages
>> should be
>> considered part of the stable API (as opposed to exception types), and
>> so, I
>> think it is, in many cases, actually wrong to test them as such.
>>
>> In some places, it makes sense to assert that certain information is
>> included
>> in the message, and then assertRaisesRegex could be used. Tim made the
>> practical argument that regexes in these circumstances introduce more
>> complexity than they're worth, and that is certainly a valid argument; I
>> can
>> agree with a general policy of "prefer assertRaisesMessage to
>> assertRaisesRegex". But I think in most places, we should only test for
>> the
>> exception type, and if more info is required, it should be structured --
>> that
>> is, presented as attributes on the exception object rather than text in
>> the
>> message.
>>
>> What do you think?
>>
>> Thanks,
>>         Shai.
>>
>> [1] https://github.com/django/django/pull/8257
>> [2] https://github.com/django/django/pull/8257#pullrequestreview-30486470
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-developers/e1e8010e-903f-45dd-8e15-
> 9f5da8150665%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/e1e8010e-903f-45dd-8e15-9f5da8150665%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM3ySnN3u58uRkXrHpJnmpzBXzQLjnj0t13di%3DxyaSM0Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to