Skip to main content

Pytest plugin for capturing and mocking connection requests.

Project description

Python versions supported

License build Code coverage Package stability codestyle

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

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.

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_quick|requests_quick|aiohttp_quick"

Handling requests:

  • Prevent 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-0.2.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

pytest_remote_response-0.2.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-remote-response-0.2.1.tar.gz.

File metadata

  • Download URL: pytest-remote-response-0.2.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for pytest-remote-response-0.2.1.tar.gz
Algorithm Hash digest
SHA256 15b3952dde89062cc445f2c2961bbcdf2224609bf402c48b4ccaba54fe24f07f
MD5 72e4866916e348c3d1353b692cb8e2d6
BLAKE2b-256 c1854220ae478bf0988677575039d51e33eccf9a30cd0ed7375c93eb9ab3f6fc

See more details on using hashes here.

File details

Details for the file pytest_remote_response-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_remote_response-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for pytest_remote_response-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca6c1a3a8f5bedff832dc10f4db42d6b6d33828a0922fb274951885e1125146b
MD5 62dc2985f32a00a8999d24fc4d781cf3
BLAKE2b-256 1084aa0fc1520c216e7e03fdc749e65c448cde2aee32afc2370a7dcf57ea9a9a

See more details on using hashes here.

Supported by

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