pytest has its own method of registering and loading custom fixtures. requests-mock provides an external fixture registered with pytest such that it is usable simply by specifying it as a parameter. There is no need to import requests-mock it simply needs to be installed and specify the argument requests_mock.

The fixture then provides the same interface as the requests_mock.Mocker letting you use requests-mock as you would expect.

>>> import pytest
>>> import requests

>>> def test_url(requests_mock):
...     requests_mock.get('', text='data')
...     assert 'data' == requests.get('').text


Some options are available to be read from pytest’s configuration mechanism.

These options are:

requests_mock_case_sensitive: (bool) Turn on case sensitivity in path matching.