[issue24134] assertRaises can behave differently

Serhiy Storchaka report at bugs.python.org
Sun May 10 14:42:46 CEST 2015


Serhiy Storchaka added the comment:

Agree, this change breaks general wrappers around assertRaises, and this breakage is unavoidable. Likely we should rollback changes in maintained releases.

The fix in Django doesn't LGTM. It depends on internal detail.

More correct fix should look like:

    def assertRaisesMessage(self, expected_exception, expected_message,
                            *args, **kwargs):
        return six.assertRaisesRegex(self, expected_exception,
                re.escape(expected_message), *args, **kwargs)

I used special sentinel because it is simple solution, but we should discourage to use this detail outside the module. Proposed patch (for 3.5) uses a little more complex approach, that doesn't attract to use implementation details. In additional, added more strict argument checking, only the msg keyword parameter now is acceptable in context manager mode. Please check changed docstrings.

It is possible also to make transition softer. Accept None as a callable and emit the deprecation warning.

----------
resolution: fixed -> 
stage: resolved -> patch review
status: closed -> open
Added file: http://bugs.python.org/file39334/assert_raises_args.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24134>
_______________________________________


More information about the Python-bugs-list mailing list