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 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)
@response.activate("urllib3")
def get_url():
http = urllib3.PoolManager()
url = "https://www.python.org"
# 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
assert res.data
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.
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 MIT licence - see the LICENCE file.
Release files for pytest-remote-response 2.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-remote-response-2.1.2.tar.gz | 29.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_remote_response-2.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.4 kB
Release files / pytest-remote-response-2.1.2.tar.gz
| Download URL | pytest-remote-response-2.1.2.tar.gz |
|---|---|
| Size | 29.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
566acf5399fdb07383e31da3cff7b0973d4e2d371dba883bc2530954bb70cd29
|
|
BLAKE2b-256 checksum How to use checksums |
64cfba5fd615143c9ee838f872e1adbfb4cdbf8d33095e329dfb4d990098dce2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / pytest_remote_response-2.1.2-py3-none-any.whl
| Download URL | pytest_remote_response-2.1.2-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a7dbefeaf70286bf9636a7f827befd0afd3bf1a47b231208cdbc82ccf99aa47
|
|
BLAKE2b-256 checksum How to use checksums |
9b1830f9009ed4099c5f089abce67e3ecdcf537eb5b3e49cb3a9f76e4e4b1f0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|