Pytest plugin for capturing and mocking connection requests.
Project description
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
Built Distribution
Hashes for pytest-remote-response-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15b3952dde89062cc445f2c2961bbcdf2224609bf402c48b4ccaba54fe24f07f |
|
MD5 | 72e4866916e348c3d1353b692cb8e2d6 |
|
BLAKE2b-256 | c1854220ae478bf0988677575039d51e33eccf9a30cd0ed7375c93eb9ab3f6fc |
Hashes for pytest_remote_response-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca6c1a3a8f5bedff832dc10f4db42d6b6d33828a0922fb274951885e1125146b |
|
MD5 | 62dc2985f32a00a8999d24fc4d781cf3 |
|
BLAKE2b-256 | 1084aa0fc1520c216e7e03fdc749e65c448cde2aee32afc2370a7dcf57ea9a9a |