Skip to main content

Pytest plugin for capturing and mocking connection requests.

Project description

Python versions supported License

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.

🔌Installation

$ pip install pytest-remote-response

or

$ git clone https://github.com/devanshshukla99/pytest-remote-response
$ 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,

💨Usage

🐍🧪Pytest plugin

The plugin works by using interceptors of different libraries which can be checked by response.available() method; these interceptors have to be applied for each pytest run using --remote={INTERCEPTOR}.

$ pytest --remote="urllib|requests|aiohttp"

Handling requests:

  • Block remote requests:

    all requests are allowed by default; one can disable them using –remote-blocked flag.

$ pytest --remote={INTERCEPTORS} --remote-blocked
  • Capture remote requests:

    the requests can be captured in a json file using --remote-capture arg.

$ pytest --remote={INTERCEPTORS} --remote-capture
  • Mock remote requests:

    the requests can be mocked using --remote-response flag.

    NOTE: Due to certain limitations, it is advised to not use this plugin in an offline environment.

$ pytest --remote={INTERCEPTORS} --remote-response

🐱‍👤Standalone package

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

Configuration:

from pytest_response import response

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

🧪 Testing

Use tox to make sure the plugin is working:

$ git clone https://github.com/devanshshukla99/pytest-remote-response
$ cd pytest-remote-response
$ tox -e py38

See tox for more info.

Licence

This plugin is licenced under a 3-clause BSD style licence - see the LICENCE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-remote-response-1.0.0.tar.gz (27.3 kB view hashes)

Uploaded Source

Built Distribution

pytest_remote_response-1.0.0-py3-none-any.whl (18.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page