[MRG+1] Fixing bug in assert_raise_message#4590
Conversation
|
Can you elaborate? Why are the non-alphanumeric characters an issue? They can be escaped, just like you did, right? But maybe we do want to keep the function around just for this purpose. I don't have a strong opinion. |
sklearn/utils/tests/test_testing.py
Outdated
|
LGTM :) |
sklearn/utils/testing.py
Outdated
There was a problem hiding this comment.
I think the docstring should be more end-user friendly:
def assert_raise_message(exception, message, function, *args, **kwargs):
"""Check that exception is raised with the expected message"""The fact that we are delegating the check to the more general assert_raises_regex is an implementation detail.
Some of our expected messages in tests have characters like " |
08cfbfb to
0b95366
Compare
assert_raise_message now only calls assert_raises_regex changing the message argument into a literal text
|
well but you could wrap that with a |
|
I think it's simpler / cleaner to keep that |
|
+1 for merge on my side. |
|
This is a nice PR with negative LOC :) |
|
feel free to merge. this solution is fine with me. |
[MRG+1] Fixing bug in assert_raise_message #4559
|
Thanks @jfraj! |
|
unfortunately this messes with the error messages, and if you nest |
|
I had not thought of that issue. I think we should restore the previous Not that the behavior expected in #4559 is not what the current I think we should follow the same behavior in our utilities for consistency. |
|
So we could restore the previous |
|
Sorry about the confusion. |
|
Ok I see. I guess there must be some deep reason for this change of behavior in 3. |
|
Actually it did not change in Python 3, this was an inconsistency introduced in our backport. Under Python 2, So the problem was definitely in our backport which was inconsistent with the behavior of the standard library wrapped by nose. |
This is a fix for #4559.
assert_raise_messagenow only calls assert_raises_regex with the message argument changed into a literal text.trashing
assert_raise_messageand using directlyassert_raises_regex, as suggested in the bug report, was not possible because some of the string message had non-alphanumeric characters.Finally, the testing has been updated to raise the expected error.