Release Notes

1.11.0

New Features

  • Exposes some public type aliases (for type hinting only, they can’t be instanciated) for the types intended to be used by requests_mock users. The following types are now exposed: - requests_mock.Context used in callbacks - requests_mock.Request used in callbacks, which is a requests.PreparedRequest proxy. - requests_mock.Callback[T] which is the callbacks type.

Bug Fixes

  • Some typing inconsistencies have been fixed. Especially for request object in signatures which is in fact a requests_mock.Request object.
  • Fix incompatibility with urllib3 >2.0.0. In 2.0.0 they default to enforcing content length checking on returned bodies in responses from the previous default of false. However the flag is still available so for compatibility we can just default the other way.

1.10.0

New Features

  • You can now set the JSON encoder for use by the json= parameter on either the mocker or an individual mocked response. This will make it easier to work with systems that encode in a specific way.

Bug Fixes

  • In some multithreading situations the mocker might try and replace an already patched object from a different thread. To make this thread safe we will put a lock around the mocker so that only one thread can work with the mocker at any time. This has to be a reentrant lock as the same thread can go through it multiple times.
  • A series of type hint fixes, most importantly the register_uri return value is not a response but a usable Matcher object.

1.9.3

Bug Fixes

  • Improvements to some type annotations that were making it confusing to use the library in an IDE.

1.9.2

Bug Fixes

  • As part of 1.9.0 we started quoting unsafe URL characters. This was done incorrectly that meant we requoted existing quoted strings. Fixes

1.9.1

Bug Fixes

  • A py.typed file is required to enable type annotations for the package. Add to pack for re-release.

1.9.0

New Features

  • Add python type hints for python 3.

Bug Fixes

  • Issue 144 - When performing a read we handled an empty byte return as an indication to close the file pointer. This is not true when you actually ask for a zero byte read so we should allow it.

1.8.0

Prelude

Makes explicit the behaviour of nested mocking.

New Features

  • Add a reset/reset_mock function to the mocker and components so that users can clear the calls and history from the Mocker without clearing all the matching that has been used.
  • Nested mocks now has a defined behaviour which is essentially a classic nesting behaviour. A mock works as normal, but in the same way that real_http=True will escalate to the outer send (typically the real send) if there is a mocker defined outside that will handle the calls.
  • Allow mocking of only a single Session object. While there has always been the option of adding just the Adapter to an existing Session, this is more difficult to work with than the Mocker workflow that is typically used. You can now pass a Session object to a Mocker and it will provide the standard workflow but limited to just that object.
  • When creating a response we now default the reason string to the appropriate string based on the status code. This can still be provided manually.
  • Make real_http variable on Mocker object public. This means you can change the value of the parameter after the object has been created. This will allow setting it in situations like pytest where you may not be able to set __init__ time options.

Bug Fixes

  • This fixes all known nesting bugs. They may not be perfect, however this is now the explicit defined behaviour and so all related bugs are closed in favour of this.
  • 124 when using response.iter_content(None) the iterator would keep returning b’’ and never finish. In most code paths the b’’ would indicate that the stream is finished, but using None we have to close it ourselves.

1.7.0

New Features

  • You can now match on the empty query string value like /path?a.

Bug Fixes

  • Pins version of requests to <3 to prepare for new release of requests in future.

1.6.0

Prelude

Increase the minimum required requests version to 2.3

Critical Issues

  • The minimum version of requests has been increase to 2.3. This simply ensures that all documented features of requests-mock are actually available. This version of requests is still quite old and if this is an issue you should either pin requests-mock to <1.6 or preferably update requests.

Bug Fixes

  • Remove weakref objects from the request/response that will allow the objects to be pickled with the regular python mechanisms.
  • If you specified a charset in the Content-Type of a response it would be ignored and overriden with either ‘utf-8’ or None depending on the type of response content passed in. If you pass this value we should honour it and perform the encoding correctly.

1.5.2

Prelude

Fix py.test plugin with py.test < 3.0

Bug Fixes

  • Fixed a bug relating to how the pytest version was being discovered that meant new versions of pytest were being treated as old versions and would receive bad configuration.
  • The py.test plugin was broken when using py.test < 3.0. The version of py.test that ships in EPEL is only 2.7 so we need to make sure we support at least that version.

1.5.1

New Features

  • The stream parameter is recorded when the request is sent and available in request history in the same was as parameters like verify or timeout.

1.5.0

Prelude

The primary repository is now at https://github.com/jamielennox/requests-mock

New Features

  • Added pytest fixture for native integration into pytest projects.

Other Notes

  • In this release the main repository was moved off of OpenStack provided infrastructure and onto github at https://github.com/jamielennox/requests-mock. OpenStack has been a great home for the project however requests-mock is a general python project with no specific relationship to OpenStack and the unfamiliar infrastructure was limiting contributes from the wider community.

1.3.0

New Features

  • Allow specifying an additional_matcher to the mocker that will call a function to allow a user to add their own custom request matching logic.

1.1.0

Prelude

Add a called_once property to the mockers.

It is now possible to make URL matching and request history not lowercase the provided URLs.

Installing the requirements for the ‘fixture’ contrib package can now be done via pip with pip install requests-mock[fixture]

New Features

  • A called_once property was added to the adapter and the mocker. This gives us an easy way to emulate mock’s assert_called_once.
  • You can pass case_sensitive=True to an adapter or set requests_mock.mock.case_sensitive = True globally to enable case sensitive matching.
  • Added ‘fixture’ to pip extras so you can install the fixture requirements with pip install requests-mock[fixture]

Upgrade Notes

  • It is recommended you add requests_mock.mock.case_sensitive = True to your base test file to globally turn on case sensitive matching as this will become the default in a 2.X release.

Bug Fixes

  • Reported in bug #1584008 all request matching is done in a case insensitive way, as a byproduct of this request history is handled in a case insensitive way. This can now be controlled by setting case_sensitive to True when creating an adapter or globally.