Skip to main content

A utility library for mocking out the `requests` Python library.

Project description

https://travis-ci.org/a-pertsev/requests-testing.svg?branch=master

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')

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

requests_testing-0.2.0-py2.py3-none-any.whl (6.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file requests_testing-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for requests_testing-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 99045f6505469ad84ffc75fbd74bfa690e8aebca45b3c98a79d2cde7d3b481dc
MD5 b921b3ed0d929c11a17e4ee4efab064e
BLAKE2b-256 558a3bf69679e02faa7ef03d3072251dc0f6c6c6de44602bed9a41a1173cbe29

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