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.

Title: unittest.assertRaisesRegex(p) example is wrong in docs
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, jtratner, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2013-06-17 01:34 by jtratner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
unittest.patch jtratner, 2013-06-17 01:34 patch for unittest.rst review
Messages (3)
msg191306 - (view) Author: Jeff Tratner (jtratner) Date: 2013-06-17 01:34
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'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')

msg192038 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-06-29 17:16
New changeset 4a714fea95ef by Terry Jan Reedy in branch '2.7':
Issue #18237: Fix assertRaisesRegexp error caought by Jeff Tratner.

New changeset b3d19f0494e7 by Terry Jan Reedy in branch '3.3':
Issue #18237: Fix assertRaisesRegexp error caought by Jeff Tratner.
msg192039 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-06-29 17:21
I went with adding ' after changing '...' to "...".

If you think you might ever submit a more substantial patch, and we hope you do, please submit a Contributor Agreement (now optionally electronic).
When processed (a week?), an * will appear after your name.
Date User Action Args
2022-04-11 14:57:47adminsetgithub: 62437
2013-06-29 17:21:52terry.reedysetstatus: open -> closed
type: behavior
messages: + msg192039

resolution: fixed
stage: resolved
2013-06-29 17:16:43python-devsetnosy: + python-dev
messages: + msg192038
2013-06-21 21:57:46terry.reedysetnosy: + terry.reedy
2013-06-17 09:08:10berker.peksagsetversions: - Python 3.1, Python 3.2, Python 3.5
2013-06-17 01:34:57jtratnercreate