This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Brian.Jones
Recipients Brian.Jones
Date 2011-07-10.16:34:48
SpamBayes Score 1.4961754e-11
Marked as misclassified No
Message-id <1310315690.64.0.281773065195.issue12527@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation here:
http://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertRaisesRegex

Indicates that, when used as a context manager, assertRaisesRegex should accept a keyword argument 'msg'. However, that doesn't appear to actually be implemented. I've just now done an hg pull, and in Lib/unittest/case.py, the source is here: 

    def assertRaisesRegex(self, expected_exception, expected_regex,
                          callable_obj=None, *args, **kwargs):
        """Asserts that the message in a raised exception matches a regex.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_regex: Regex (re pattern object or string) expected
                    to be found in error message.
            callable_obj: Function to be called.
            msg: Optional message used in case of failure. Can only be used
                    when assertRaisesRegex is used as a context manager.
            args: Extra args.
            kwargs: Extra kwargs.
        """
        context = _AssertRaisesContext(expected_exception, self, callable_obj,
                                       expected_regex)

        return context.handle('assertRaisesRegex', callable_obj, args, kwargs)

I noticed this after attempting some simple example uses of assertRaisesRegex. Perhaps I'm just missing something that will be made obvious to others by seeing them. These are just various attempts to get my msg shown somewhere in the output: 

#!/usr/bin/env python3.3
import unittest

class TestInt(unittest.TestCase):
    def test_intfail(self):
        # this test should *not* fail, and doesn't
        with self.assertRaisesRegex(ValueError, 'literal'):
            int('XYZ')

    def test_intfail2(self):
        # should not fail, and doesn't
        with self.assertRaisesRegex(ValueError, 'lambda', msg='Foo!'):
            int('ABC')

    def test_intfail3(self):
        # should fail, and does, but no msg to be found.
        with self.assertRaisesRegex(ValueError, 'literal', msg='Foo!'):
            int(1)

    def test_intfail4(self):
        # should fail, and does, but no msg to be found.
        with self.assertRaisesRegex(TypeError, 'literal', msg='Foo!'):
            int('ABC')

if __name__ == '__main__':
    unittest.main()
History
Date User Action Args
2011-07-10 16:34:50Brian.Jonessetrecipients: + Brian.Jones
2011-07-10 16:34:50Brian.Jonessetmessageid: <1310315690.64.0.281773065195.issue12527@psf.upfronthosting.co.za>
2011-07-10 16:34:50Brian.Joneslinkissue12527 messages
2011-07-10 16:34:48Brian.Jonescreate