August 2018
Beginner
160 pages
4h 8m
English
The pytest-mock plugin provides a fixture that allows a smoother integration between pytest and the unittest.mock (https://docs.python.org/3/library/unittest.mock.html) module of the standard library. It provides functionality similar to the built-in monkeypatch fixture, but the mock objects produced by unittest.mock also record information on how they are accessed. This makes many common testing tasks easier, such as verifying that a mocked function has been called, and with which arguments.
The plugin provides a mocker fixture that can be used for patching classes and methods. Using the getpass example from the last chapter, here is how you could write it using this plugin:
import getpassdef test_login_success(mocker): mocked ...
Read now
Unlock full access