[issue18237] unittest.assertRaisesRegex(p) example is wrong in docs

Jeff Tratner report at bugs.python.org
Mon Jun 17 03:34:57 CEST 2013


New submission from Jeff Tratner:

One of the examples for assertRaisesRegex(p) is wrong by one character.

Current is:

self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ$',
                        int, 'XYZ')

The $ at the end is wrong because the actual error message is "ValueError: invalid literal for int() with base 10: 'XYZ'" (with a ``'`` at the end).  Two options for fixing.

Option 1 - remove $
self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ',
                        int, 'XYZ')
Option 2 - add '

self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ\'$',
                        int, 'XYZ')

Same example is shown for assertRaisesRegex, so applies to both.

And for completeness...here's something you can run to see the error [couldn't figure out how to attach two files]:

import unittest
class MyTest(unittest.TestCase):
    def test_example(self):
        # this fails
        self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ$',
                        int, 'XYZ')
    def test_option1(self):
        self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ',
                                int, 'XYZ')
    def test_option2(self):
        self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ\'$',
                                int, 'XYZ')

unittest.main()

----------
assignee: docs at python
components: Documentation
files: unittest.patch
keywords: patch
messages: 191306
nosy: docs at python, jtratner
priority: normal
severity: normal
status: open
title: unittest.assertRaisesRegex(p) example is wrong in docs
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file30615/unittest.patch

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


More information about the Python-bugs-list mailing list