Skip to main content

Provides an adapter for mocking HTTP requests for unit test purposes.

Project description

Currently a very basic module that provides an adapter for requests that mocks network activity for unit test purposes.

How to use

This code assumes your HTTP client is written in a way that enables passing a custom Session object. When that’s the case, all you have to do is to mount the adapter to answer for a specific prefix:

>>> import requests
>>> from requests_testadapter import TestAdapter
>>> s = requests.Session()
>>> s.mount('http://', TestAdapter(b'Mock!', status=404))
>>> r = s.get('')
>>> r.status_code
>>> r.text

You can also specify a headers dictionary as a keyword argument to TestAdapter.

How do I run the tests?

The easiest way would be to extract the source tarball and run:

$ python test/

Change Log


  • initial published version


Glued together by Łukasz Langa.

Project details

Download files

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

Files for requests-testadapter, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size requests-testadapter-0.1.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

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