Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

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


Release history Release notifications

This version
History Node

0.2.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
requests_testing-0.2.0-py2.py3-none-any.whl (6.8 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Nov 24, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page