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

Mock is equal to ANY but MagicMock is not #72921

Closed
rafaelfonseca mannequin opened this issue Nov 18, 2016 · 8 comments
Closed

Mock is equal to ANY but MagicMock is not #72921

rafaelfonseca mannequin opened this issue Nov 18, 2016 · 8 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rafaelfonseca
Copy link
Mannequin

rafaelfonseca mannequin commented Nov 18, 2016

BPO 28735
Nosy @voidspace, @berkerpeksag, @serhiy-storchaka, @kushaldas, @zhangyangyu
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • magicmock_eq.patch
  • 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 = None
    closed_at = <Date 2017-01-21.21:21:01.974>
    created_at = <Date 2016-11-18.16:07:14.552>
    labels = ['3.7', 'type-bug', 'library']
    title = 'Mock is equal to ANY but MagicMock is not'
    updated_at = <Date 2017-03-31.16:36:21.583>
    user = 'https://bugs.python.org/rafaelfonseca'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:21.583>
    actor = 'dstufft'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-01-21.21:21:01.974>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-11-18.16:07:14.552>
    creator = 'rafael.fonseca'
    dependencies = []
    files = ['46361']
    hgrepos = []
    issue_num = 28735
    keywords = ['patch']
    message_count = 8.0
    messages = ['281135', '285908', '285909', '285910', '285918', '285925', '285966', '285967']
    nosy_count = 7.0
    nosy_names = ['rafael.fonseca', 'michael.foord', 'python-dev', 'berker.peksag', 'serhiy.storchaka', 'kushal.das', 'xiang.zhang']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28735'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @rafaelfonseca
    Copy link
    Mannequin Author

    rafaelfonseca mannequin commented Nov 18, 2016

    On Python 3.5.2 mock.Mock() is equal to mock.ANY, but mock.MagicMock() is not.

    Minimal example:

    In Python 3.5.2:
    >>> from unittest import mock
    >>> mock.Mock() == mock.ANY
    True
    >>> mock.ANY == mock.Mock()
    True
    >>> mock.MagicMock() == mock.ANY
    False
    >>> mock.ANY == mock.MagicMock()
    True

    @rafaelfonseca rafaelfonseca mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 18, 2016
    @SilentGhost SilentGhost mannequin added the 3.7 (EOL) end of life label Nov 18, 2016
    @kushaldas
    Copy link
    Member

    From a checkout in last week.

    Python 3.7.0a0 (default:c163a76163f7, Jan 15 2017, 22:20:24) 
    [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from unittest import mock
    >>> mock.ANY == mock.Mock() 
    True
    >>> mock.ANY == mock.MagicMock() 
    True

    @zhangyangyu
    Copy link
    Member

    Kushal I think the OP is reporting mock.MagicMock() == mock.ANY is False while mock.ANY == mock.MagicMock() is True which is still the case in 3.7. A related issue is bpo-25195. In that issue Serhiy has mentioned this behaviour(http://bugs.python.org/issue25195#msg259822).

    @kushaldas
    Copy link
    Member

    Now I understood, thanks. I think I should have more coffee before commenting on bugs :)

    @serhiy-storchaka
    Copy link
    Member

    Proposed patch fixes comparing MagicMock with ANY.

    @berkerpeksag
    Copy link
    Member

    Serhiy's patch looks pretty good to me, thanks! Also, thanks for the report, Rafael. I definitely forgot to fix this case after fixing bpo-25195.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 21, 2017

    New changeset 442eb26b1ca4 by Serhiy Storchaka in branch '3.5':
    Issue bpo-28735: Fixed the comparison of mock.MagickMock with mock.ANY.
    https://hg.python.org/cpython/rev/442eb26b1ca4

    New changeset 4a38781538f7 by Serhiy Storchaka in branch '3.6':
    Issue bpo-28735: Fixed the comparison of mock.MagickMock with mock.ANY.
    https://hg.python.org/cpython/rev/4a38781538f7

    New changeset 597515fcb343 by Serhiy Storchaka in branch 'default':
    Issue bpo-28735: Fixed the comparison of mock.MagickMock with mock.ANY.
    https://hg.python.org/cpython/rev/597515fcb343

    @serhiy-storchaka
    Copy link
    Member

    Thanks Berker.

    Maybe _Call.__eq__ also should return NotImplemented in some cases, but I don't have a demonstrating example.

    @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
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants