[New-bugs-announce] [issue12527] assertRaisesRegex doc'd with 'msg' arg, but it's not implemented?
Brian Jones
report at bugs.python.org
Sun Jul 10 18:34:50 CEST 2011
New submission from Brian Jones <bkjones at gmail.com>:
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()
----------
components: Library (Lib)
messages: 140084
nosy: Brian.Jones
priority: normal
severity: normal
status: open
title: assertRaisesRegex doc'd with 'msg' arg, but it's not implemented?
type: behavior
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12527>
_______________________________________
More information about the New-bugs-announce
mailing list