It’s just a fact of life, as code grows eventually you will need to start adding mocks to your test suite. What started as a cute little two class project is now talking to external services and you cannot test it comfortably anymore. That’s why Python ships with unittest.mock, a powerful part of the standard library for stubbing dependencies and mocking side effects. However, unittest.mock is not particularly intuitive. I’ve found myself many times wondering why my go-to recipe does not work for a particular case, so I’ve put together this cheatsheet to help myself and others get mocks working quickly. You can find the code examples in the article’s Github repository. I’ll be using Python 3.6, if you’re using 3.2 or below you’ll need to use the mock PyPI package. The examples are written using unittest.TestCase classes for simplicity in executing them without dependencies, but you could write them....
why I have to register to read the whole article? are you kidding? lol