Plugins¶
So far, we have focused on using mock
directly. However, there are many plugins that can help with mocking, such as
pytest-mock, which, amongst other
things, provides a mocker fixture. One advantage is that the fixture cleans
up after itself, so you don’t need to use a with block, as we did in our
examples. mocker.spy is also a handy
simplification based on wraps and autospec.
There are also some specialised mocking libraries:
For mocking database access, the following are suitable:
To test HTTP servers, you can use pytest-httpserver.
Other tools for various requirements are