Pytest plugin for capturing and mocking connection requests.

pytest-plugin, python3
pip install pytest-remote-response==2.0.0



Python versions supported License Digital Object Identifier

build Documentation Status Code coverage Package stability codestyle

This package provides a plugin for pytest framework for capturing and mocking connection requests during the test run.

Inspired by pook and pytest-responses.

Get started using the documentation and getting-started.


$ pip install pytest-remote-response


$ git clone
$ cd pytest-remote-response
$ pip install .

The plugin will register automatically with pytest framework and will be ready to use.

💁🏻‍♀️Supported Clients

Currently, pytest-remote-response supports,


🐍🧪Pytest plugin

The plugin works by applying monkeypatches of interceptors for different libraries using a wrapper response.activate. The interceptors when applied can capture, prevent or mock the connection request.

The available interceptors are listed in response.available method.

Example of using the decorator:

import urllib3
from pytest_response import response

response.configure(remote=True, capture=True, response=False)

def get_url():
    http = urllib3.PoolManager()
    url = ""

    # Since the interceptors are in response mode, the response data and headers
    # will be spoofed with saved data in the database;
    # if the query comes back empty, this request will
    # error out with :class:`pytest_response.exceptions.ResponseNotFound`
    res = http.request("GET", url)
    assert res.status == 200

Handling requests:

  • Block remote requests:
    all requests are allowed by default; one can disable them using --remote-block flag
$ pytest --remote-block
  • Capture remote requests:
    the requests can be captured in a sqlite3 database using --remote-capture arg
$ pytest --remote-capture
  • Mock remote requests:
    the requests can be mocked using --remote-response
$ pytest --remote-response

🐱‍👤Standalone package

The tools implemented in this package can be easily ported to any other application, with mimial config required.


from pytest_response import response

response.setup_database({DUMP FILE}){INTERCEPTOR})

🧪 Testing

Use tox to make sure the plugin is working:

$ git clone
$ cd pytest-remote-response
$ tox -e py38

See tox for more info.


This plugin is licenced under a MIT licence - see the LICENCE file.