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.

Author ElizabethU
Recipients ElizabethU
Date 2019-07-11.05:12:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562821924.84.0.134272462767.issue37555@roundup.psfhosted.org>
In-reply-to
Content
I have a test that goes something like:

```
@patch('a.place.to.patch')
def test_a_thing_calls_what_it_should(self, my_mock):
    # Set up logic here
    my_mock.assert_has_calls([
        call(
            ANY,
            Decimal('20')
        ),
        call(
            ANY,
            Decimal('10')
        )
    ])```

Which fails, where my_mock.call_args_list looks like 

```
[(<A Django Model>, Decimal('20')), (<A Django Model>, Decimal('10'))]
```

This seems like wrong behavior. ANY should be happy to be compared to anything, even a Django object. Doing some digging, I found that on line 340 of cpython/Lib/unittest/mock.py _CallList is overriding __contains__ and comparing each item in the tuples with what I'd passed in to assert_has_calls on the right, which means that instead of using ANY.__eq__, it's calling the Django model's __eq__ with ANY as an argument. Django first checks if the thing it's comparing to is another Django model, and returns False if not. So, <DjangoModel> == ANY is False, but ANY == <DjangoModel> is True. I know that this could also be considered a bug with Django, and I plan to file one with them too, but I don't see any downside to improving the mock library to be more defensive in honoring ANY over any other custom class's overridden __eq__ method.
History
Date User Action Args
2019-07-11 05:12:04ElizabethUsetrecipients: + ElizabethU
2019-07-11 05:12:04ElizabethUsetmessageid: <1562821924.84.0.134272462767.issue37555@roundup.psfhosted.org>
2019-07-11 05:12:04ElizabethUlinkissue37555 messages
2019-07-11 05:12:04ElizabethUcreate