Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between python mock and magic mock? [duplicate]

What is difference between python mock and magic mock, because I could see

>>> dir(Mock()) == dir(MagicMock())
True

when to use mock obj & when to use MagicMock obj??

like image 646
Vb407 Avatar asked Apr 17 '26 10:04

Vb407


1 Answers

MagicMock is a subclass of Mock with default implementations of many magic methods. You can use MagicMock without having to configure the magic methods yourself.

I suppose the code above is to affect most of magic methods to your mock automatically

check this guide it may help you Magic Methods

and official doc https://docs.python.org/2/reference/datamodel.html#special-method-names

like image 194
JustGreat Avatar answered Apr 19 '26 00:04

JustGreat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!