A utility library for mocking out the requests Python library.
Starting with requests-testing
Here is a simple example:
import requests
import requests_testing
@requests_testing.activate
def example():
requests_testing.add(request={'url': 'http://example.com'}, response={'body': 'ok'})
resp = requests.get('http://example.com')
assert resp.text == 'ok'
assert len(requests_testing.calls) == 1
assert requests_testing.calls[0].request.url == 'http://example.com/'
If your attempts to fetch a url which doesn’t hit a match, ConnectionError will raise:
import requests
import requests_testing
from requests.exceptions import ConnectionError
@responses.activate
def test_error():
with pytest.raises(ConnectionError):
requests.get('http://example.com')
Metadata
Release files for requests-testing 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| requests_testing-0.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Release files / requests_testing-0.2.0-py2.py3-none-any.whl
| Download URL | requests_testing-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
99045f6505469ad84ffc75fbd74bfa690e8aebca45b3c98a79d2cde7d3b481dc
|
|
BLAKE2b-256 checksum How to use checksums |
558a3bf69679e02faa7ef03d3072251dc0f6c6c6de44602bed9a41a1173cbe29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |