requests_mock package

Subpackages

requests_mock.adapter module

class requests_mock.adapter.Adapter[source]

Bases: requests.adapters.BaseAdapter

A fake adapter than can return predefined responses.

add_matcher(matcher)[source]

Register a custom matcher.

A matcher is a callable that takes a requests.Request and returns a requests.Response if it matches or None if not.

Parameters:matcher (callable) – The matcher to execute.
close()[source]
last_request[source]

Retrieve the latest request sent

register_uri(method, url, response_list=None, **kwargs)[source]

Register a new URI match and fake response.

Parameters:
  • method (str) – The HTTP method to match.
  • url (str) – The URL to match.
send(request, **kwargs)[source]

requests_mock.exceptions module

exception requests_mock.exceptions.MockException[source]

Bases: exceptions.Exception

Base Exception for library

exception requests_mock.exceptions.NoMockAddress(request)[source]

Bases: requests_mock.exceptions.MockException

The requested URL was not mocked

requests_mock.fixture module

Module contents

class requests_mock.Adapter

Bases: requests.adapters.BaseAdapter

A fake adapter than can return predefined responses.

add_matcher(matcher)

Register a custom matcher.

A matcher is a callable that takes a requests.Request and returns a requests.Response if it matches or None if not.

Parameters:matcher (callable) – The matcher to execute.
close()
last_request

Retrieve the latest request sent

register_uri(method, url, response_list=None, **kwargs)

Register a new URI match and fake response.

Parameters:
  • method (str) – The HTTP method to match.
  • url (str) – The URL to match.
send(request, **kwargs)
class requests_mock.Mocker(**kwargs)

Bases: requests_mock.mocker.MockerCore

The standard entry point for mock Adapter loading.

class requests_mock.MockerCore(**kwargs)

Bases: object

A wrapper around common mocking functions.

Automate the process of mocking the requests library. This will keep the same general options available and prevent repeating code.

start()

Start mocking requests.

Install the adapter and the wrappers required to intercept requests.

stop()

Stop mocking requests.

This should have no impact if mocking has not been started.

exception requests_mock.MockException

Bases: exceptions.Exception

Base Exception for library

exception requests_mock.NoMockAddress(request)

Bases: requests_mock.exceptions.MockException

The requested URL was not mocked

Table Of Contents

This Page