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 iritkatriel
Recipients Indy, iritkatriel
Date 2020-10-14.23:08:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1602716883.42.0.715399785028.issue42019@roundup.psfhosted.org>
In-reply-to
Content
I don't know whether this is intended behaviour of not, but it seems that MagicMock's __init__ is setting the magic methods, every time a mock instance is created. I was able to achieve what you tried to write with this class definition - it sets __len__ after super.__init__ has done what it needs to do.

class MagicMockChild(MagicMock):
    def __init__(self):
        super().__init__()
        self.__len__ = lambda self : 9

This is not intended to be a satisfying answer, just to show what's going on.
History
Date User Action Args
2020-10-14 23:08:03iritkatrielsetrecipients: + iritkatriel, Indy
2020-10-14 23:08:03iritkatrielsetmessageid: <1602716883.42.0.715399785028.issue42019@roundup.psfhosted.org>
2020-10-14 23:08:03iritkatriellinkissue42019 messages
2020-10-14 23:08:03iritkatrielcreate