Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

longMessage attribute is ignored in unittest.TestCase.assertRegexpMatches etc #64561

Closed
Dhara mannequin opened this issue Jan 23, 2014 · 15 comments
Closed

longMessage attribute is ignored in unittest.TestCase.assertRegexpMatches etc #64561

Dhara mannequin opened this issue Jan 23, 2014 · 15 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Dhara
Copy link
Mannequin

Dhara mannequin commented Jan 23, 2014

BPO 20362
Nosy @rbtcollins, @ezio-melotti, @voidspace, @wiggin15, @berkerpeksag
Files
  • issue20362.diff
  • 20362_py27.patch: 2.7 patch
  • 20362_py35.patch: 3.5 patch
  • 20362_py35_v2.patch: 3.5 patch v2
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/berkerpeksag'
    closed_at = <Date 2015-08-19.23:24:52.018>
    created_at = <Date 2014-01-23.09:39:37.307>
    labels = ['easy', 'type-bug', 'library']
    title = 'longMessage attribute is ignored in unittest.TestCase.assertRegexpMatches etc'
    updated_at = <Date 2015-08-19.23:24:52.016>
    user = 'https://bugs.python.org/Dhara'

    bugs.python.org fields:

    activity = <Date 2015-08-19.23:24:52.016>
    actor = 'rbcollins'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2015-08-19.23:24:52.018>
    closer = 'rbcollins'
    components = ['Library (Lib)']
    creation = <Date 2014-01-23.09:39:37.307>
    creator = 'Dhara'
    dependencies = []
    files = ['35274', '38958', '38960', '40115']
    hgrepos = []
    issue_num = 20362
    keywords = ['patch', 'easy']
    message_count = 15.0
    messages = ['208899', '218733', '240737', '240740', '240745', '240836', '241635', '242880', '247888', '247920', '247922', '247932', '248422', '248862', '248865']
    nosy_count = 9.0
    nosy_names = ['bronger', 'rbcollins', 'ezio.melotti', 'michael.foord', 'wiggin15', 'python-dev', 'berker.peksag', 'Dhara', 'copper-head']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20362'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @Dhara
    Copy link
    Mannequin Author

    Dhara mannequin commented Jan 23, 2014

    Various assert methods added in version 2.7 ignore the longMessage attribute:
    http://docs.python.org/2.7/library/unittest.html#unittest.TestCase.longMessage

    For example when matching regular expressions using unittest.TestCase.assertRegexpMatches, the following error is generated:

    AssertionError: <custom short message>: '<regexp>' not found in '<text>'

    Since longMessage is ignored, and the text to be matched can be pages long, the error messages are impossibly long.

    [See also: http://stackoverflow.com/questions/21157905/suppress-supplementary-error-message-from-unit-test]

    @Dhara Dhara mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 23, 2014
    @berkerpeksag
    Copy link
    Member

    I've added missing self._formatMessage() functions to assertRegex and assertNotRegex asserts.

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Apr 13, 2015

    This fix has been retested with 2.7, I'm uploading the relevant patch files.

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Apr 13, 2015

    Modified to work with 3.5. Attaching patch file.

    @berkerpeksag
    Copy link
    Member

    Thanks for the patches, Ilia. The one for 2.7 looks good.

    Reviewing 20362_py35.patch:

    • Looks almost identical to bpo-20362.diff except style changes and the two comments below, right?

      •        self.assertIn("'kot'", e.args[0])
        

      Why did you remove this line?

      • assertNotRegexpMatches = _deprecate(assertNotRegex)

      This looks like an unrelated change, but I think it can be committed. Thanks for the catch!

    • The tests should be updated to use assertRegex and assertNotRegex

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Apr 14, 2015

    Thanks for the quick response, Berker! Let me address your comments in the order you made them.

    #1: removing checking for "kot" in the exception args.
    This line was causing the tests to fail, which is how I noticed it. The reason it fails (I think) is caused by the changes made in the patch. Namely, the fact that we're strictly sticking to longMessage=False means the custom message passed by the user (in this particular case that's "Message") is be the *only* thing sent to AssertionError. Thus checking for the presence of "kot" in this error's args doesn't seem to make much sense and will simply keep breaking our tests.
    Now it goes without saying that I may have missed something, please let me know if that's the case.

    #2
    For some reason I got the impression that the tests should be using the newer method names, but since using the old ones didn't break them on my machine, I've updated the patch file accordingly. I'll upload it pending your feedback regarding #1.

    Glad to help!
    Ilia.

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Apr 20, 2015

    Hi Berker!

    I hope all's well on your end. Let me know if you have questions about the reasoning behind my changes.

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented May 11, 2015

    Hi there!

    I was wondering if anyone had a chance to take a look at this :)

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Aug 2, 2015

    I notice folks have been subscribing to this. Any chance we could review it and merge? :)

    @wiggin15
    Copy link
    Mannequin

    wiggin15 mannequin commented Aug 3, 2015

    • The removal of the 'kot' test is ok. That's what the fix is about. With longMessage set to False, we should only see the custom message, 'Message', and not the message about the regex that contains 'kot'.
    • Please update the patch for 3.5 to use assertRegex and assertNotRegex in the assertMessages call. These are the new names. With the current patch, the tests throw deprecation warnings.

    Other than that the patch looks good (I am not a committer, though, so I can't help further).

    @berkerpeksag
    Copy link
    Member

    Sorry for my late response, Ilia. Your reply to my first question looks correct to me. Please send your updated patch and I'll apply.

    @berkerpeksag berkerpeksag self-assigned this Aug 3, 2015
    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Aug 3, 2015

    Thanks for the feedback, folks. Adding the updated patch.

    @copper-head
    Copy link
    Mannequin

    copper-head mannequin commented Aug 11, 2015

    Bump :)

    Let's close this one, guys!

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 19, 2015

    New changeset 738de9a9a3ea by Robert Collins in branch '3.5':
    Issue bpo-20362: Honour TestCase.longMessage correctly in assertRegex.
    https://hg.python.org/cpython/rev/738de9a9a3ea

    New changeset 977e60f597de by Robert Collins in branch 'default':
    Issue bpo-20362: Honour TestCase.longMessage correctly in assertRegex.
    https://hg.python.org/cpython/rev/977e60f597de

    @rbtcollins
    Copy link
    Member

    Thanks for the patch, applied to 3.5 and 3.6.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants