Over my career, I’ve programmed in many different languages, with a special focus on Java and JavaScript. Recently I’ve been writing a lot of Python code. I’m loving the experience, it’s super powerful and easy to use! The simplicity permeates it all, and tests are not an exception. I left behind -temporarily- my JUnit, Mockito, Jasmine, and SinonJS days by and . pytest unittest.mock Especially, the is amazing! But, it’s -in some aspects- so different, compared to the other libraries I used before, that I took some time to write a Gist to help me and others better understand how it works. Mock Object Library You’ll find in the Gist below, different test classes for each different functionality/possibility: . Uses “non-defined” methods from a instance. As you can see, there’s no need to use a specification/interface, as you would need for Mockito. * TestSimple MagicMock . Uses the field for returning custom values when treating the mock as a function or class method. You can also capture how many times the mock has been called and the parameters passed to it. * TestReturnValue return_value . Uses the field for defining a function that would be used when executing the mock as a function or class method. You can use this function for raising exceptions or just executing some logic before returning. * TestSideEffect side_effect . Uses the and fields for defining an object or class that would be used as the blueprint/interface of the resulting mock. This is similar to how Mockito works. One field ( ) allows you to expand the interface, but the other ( ) not. * TestSpec spec spec_set spec spec_set Uses the field for defining an object or class that would be wrapped with a MagicMock instance. The original object behavior would be there, but you can expand it! * TestWraps . wraps . Uses the function for changing the behavior of external functions and/or classes. This is fundamental when you need to change collaborators behavior, specially when these are not part of your codebase. * TestPatch patch Hope you find useful this information. I learned most of the things shown here programming the for . tests AccessBot Thanks for reading! Read behind a paywall . here